Search this Website

 

Ubuntu

UNIX

how do i pass a variable to awk

Category: UNIX-Unix Beginner

how do i pass a variable to awk?

i have an awk statement where i need to pass an environment variable but i cannot get it to work:

my evironment varible examples below:
$file1=/dev/fs/file.new
$file2=/dev/fs/file.old

code below:

awk -f"|" '
begin {
while( getline < "$file1" )
{ arr[$1]=1 }
} arr[($1)] != 1 { print }
' $file2

i cannot hard code the file names into the awk statement. i need to apss the file name as a varibale. but my above awk is not reading $file1 as the value it is defined as in the environment.


Read More...

very simple argument in scripting question

Category: UNIX-Unix Beginner

very simple argument in scripting question

i tried to do a search, but it couldnt pinpoint what my answer since using limited but broad keywords. sorry in advance ; ;

im limited to using bourne shell scripting only, atm i have the following code (just the heading part of it)

code:
...
...
# variable declaration
# ====================

linecount=1
eofflag=0
matched=0

# ask for player name

echo -n "player name? " # < problems with this
# and store it to the variable
read srcstr
...
...

read -n1 keypress # < problems with this

...
...

first my echo is showing the -n, and second my read is giving me "is not an identifier" error msg. i tried both echo -n and read -n1 in plain shell environment (non-scripting) and it works fine. but why it wont work when i put them in scripting file. and what are my alternatives?

thanks for any help.... couldnt find any answer to my question in google, and i'm stuck and desperate.


Read More...

delete pattern files in sub directories

Category: UNIX-Unix Beginner

delete pattern files in sub directories

hello friends,

i am compiling some set of sql scripts in a set of sub directories demoed as below. after compiling log files are being created.
each and every time after compiling time i had to go subdir by subdir to delete the log files. i am sure there should be simple way to look for all log files and delete them.

could someone please provide the script/command to do so.

thanks
-durga

sql files
maindir/dir1/a.sql
maindir/dir1/b.sql
maindir/dir2/c.sql
maindir/dir2/dir3/d.sql
...
...
...

log files
maindir/dir1/a.log
maindir/dir1/b.log
maindir/dir2/c.log
maindir/dir2/dir3/d.log
...
...


Read More...

delete compressed files from year 2005

Category: UNIX-Unix Beginner

delete compressed files from year 2005

i'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .z extension on them. i tried using the awk utility but the syntax is incorrect. i don't know how to use a wildcard to capture all the compressed files. here's the code i used

( ls -lr | awk '$8 == "2005" && $9 == ".z" {print $0}' )

any suggestions on how to do this would be greatly appreciated.


Read More...

delete files using awk

Category: UNIX-Unix Beginner

delete files using awk

the code below works for finding files created in 2005 that are compressed.
how do i delete these files?
do i substitute rm -f for the print $0 ?

here's the code that finds the 2005 compressed files

(ls -lr | awk '$8 == "2005" && $9 ~ /z$/ {print $0}')

thanks for your help!!!


Read More...

new solaris box how do i tell if its raided

Category: UNIX-Unix Beginner

new solaris box how do i tell if its raided

got a new machine in that was set up prior to receipt, how can i tell if the drives are raided and if so what raid level was used on solaris 8?

thanks,


Read More...

aixcreating user with username more than 8 chars

Category: UNIX-Unix Beginner


Read More...

return value

Category: UNIX-Unix Beginner

return value

how do i find out the return value of a shell script or program in unix?

is there a command to find that out??


Read More...

extracting filename from fullpath

Category: UNIX-Unix Beginner

extracting filename from fullpath

hi,
any help on this would be very appreciated.

i capture the full path & filename in a variable like (varfile=/home/user/extfile.txt). now in my shell script i have to use only the filename part i.e. extfile.txt. how do i extract only the filename part from the variable?


Read More...

ftp help

Category: UNIX-Unix Beginner

ftp help

does anyone know why i can't transfer a directory containing files from a remote directory to a local directory using psftp. if i take the file out of the directory but put it in the same place as where the directory was then i can get that file using psftp's get file command. does not work for the directory (holding folder) though. could it have something to do with permissions?


Read More...