What awk command will test a string to determine if it is a valid file name?
With the following awk statement I isolate the lines from the inputfile that might contain a filename, then I attempt to test the possible filename which is always in $4 from each line. However it is not working at all as i do not think the system command gets passed $4 from awk. Have been struggling with this all day
Quote:
if ( $1 ~ /^$/ )
then
system("ls $4;echo $?")
{ print $0
means empty string (literally line which has beginning and end and nothing between them).
Then 'then'. I usually don't use it in awk scripts. My awk gives no error if I put it after 'if'-statement, but I'm not sure that its behavior is correct.
Now your system call:
Quote:
Originally Posted by Arsenalman
system("ls $4;echo $?")
{ print $0
Obviously you meant, that 'system' will invoke 'ls $4', print the exit code of the command back to awk script and then awk will print it with 'print $0'. It doesn't work such way. :-)
'system' simply calls a system command and does not return the output of the command to awk. What it returns is....I'll give you three guesses... Yeahh.. The exit code of the invoked command.
so
would do in your case, but it is better to use a special shell command which checks whether its argument is a file: 'test -f'. It returns 1 if the tested thing is not a file, and 0 if it is, so we have
now we need to check what the exit code was
You can do it even smarter. You don't need to store the exit code in an explicit variable. You can use 'system' straight in your 'if' condition:
I hope I could help
Franklin52, sidorenko thank you both for your valuable input, it has help me take further today, still no cigar. Will definitely post when I hit jack pot or getting close and need a little more guidance.
Hello everybody,
I would like modify some strings using sed or another command line with the content file.
For example:
- {fqdn: "server-01" , ip: "server-01"}
- {fqdn: "server-02" , ip: "server-02"}
- {fqdn: "server-03" , ip: "server-03"}
- {fqdn: "server-04" , ip: "server-04"}
My... (4 Replies)
I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: -->
cat comp.pkglist
Package list: nss-util-devel-3.28.4-1.el6_9.x86_64
Version Change: 3.28.4 -->... (1 Reply)
Hi,
I want to do caseless string comparision using test command
for eg: Ind_f="y"
test "$Ind_f" == "y|Y"
i tried , ** , nothing worked.
any thoughts on how to do case insensitive string comparison using test command without converting to any particular case using typeset or tr? (8 Replies)
I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios.
Cat test
Nov 10, 2012 5:17:53 AM
INFO: Request Type
Line 1.... (5 Replies)
here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb
cat dump.sql
INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
AWK Command parse a file based on string.
I am trying to write a shell script to parse a file based on a string and move the content of the file to another file.
Here is scenario.
File content below
Mime-Version: 1.0
Content-Type: multipart/mixed;
... (2 Replies)
This is the code:
while test 1 -eq 1
do
read a
$a
if test $a = stop
then
break
fi
done
I read a command on every loop an execute it.
I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test.
For example echo hello.
Now the... (1 Reply)
My process creates file like
abc.20090427.txt i.e abc.date.txt
next time when my process it has to detect if any previous "abc" exist.
If exist then move to archive and create a new abc file.
I am using test command but it doesnt allow wild card.
if ]
then
mv abc.*.txt... (7 Replies)
Can someone delve more into what below test command do?
if ; then
I know -t is for file descriptor
-t
file descriptor FD (stdout by default) is opened on a terminal
But not sure how to relate to it..
$1 is supposedly first argument, so let's say if
scriptname:... (2 Replies)