Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Adding variable at end of the row
Name: nimi Date: July 4, 2006 at 20:16:36 Pacific OS: SUN SOLARIS CPU/Ram: NA Product: SUN
Comment:
Hi,
How do I append the filename to the end of every rows in a text file?
I used the following command VAR="MSS" sed 's/$/|'"${VAR}"'/' ABC.txt > test1.txt mv test1.txt ABC.txt
i got what i wanted.
how do u use awk for the same scenario?
VAR="MSS" awk ' {print $0"|"ABC.txt} ' $VAR ???
well, which one is a better way, sed or awk?
Thanks Nimi
0
Response Number 3
Name: nails Date: July 5, 2006 at 08:57:44 Pacific
Reply:
My original post assumed the actual filename was the replacement text. That's why I was able to use awk's FILENAME internal variable. You can embed shell variables in awk:
awk ' { print $0"|""'"$VAR"'" } ' ABC.txt
but I prefer to pass the variable's value to the awk script:
awk ' { print $0"|"v1 } ' v1="$VAR" ABC.txt
In this case, which is better - awk or sed? It's a personal preference. I prefer the sed version.
Summary: Hi, I would like to set a cron job from 9th to the end of the month. So I did it like: 0 1 9-31 * * echo "Testing CronJob" But I am not sure what will happen for Febraury and for 30 day months like ...
Summary: Why do you have to use sed or awk? You said it needs to be appended to the end of the file. Why not just use: print "<string value>" >> <filename> ...
Summary: Hello, For my application, I have input dat ( around 1000 input files) which are simple ascii text files. These files were created on Windows platform. and I ftp ed to unix plaftorm to test my applica...