![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ignore some lines with specific words from file comparison | jakSun8 | Shell Programming and Scripting | 2 | 03-12-2008 09:11 PM |
| Reading a file and writing the file name to a param file. | thebeginer | UNIX for Advanced & Expert Users | 1 | 10-05-2007 01:38 PM |
| reading variables from a file | ttshell | Shell Programming and Scripting | 4 | 03-13-2006 08:04 AM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 02:25 AM |
| Reading a CSV file into shell variables problem | multidogzoomom | Shell Programming and Scripting | 6 | 10-11-2005 01:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
file.txt contains
------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- #!/bin/ksh while read x y do echo "${x}.ksh ${y}" done < file.txt issues: 1) It doesnt ignore the 2nd line with # in the beginning.how to do it here. 2) Can we use awk or sed for the file reading? if yes then how? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
awk
Hi,
Try this one: Code:
awk '{
if (index($1,"#")==0)
print $1".ksh"" "$2
}' filename
|
|
#3
|
|||
|
|||
|
try using
Quote:
|
|
#4
|
|||
|
|||
|
OK..chk this cmdline out
sed '/^#/d;s/\(.*\) \(.*\)/\1.sh \2/' file.txt The above is the best fix with sed cmd. Looping with while or for is not recommended unless u feel the need for the same. But if still u insist with while cmd then it goes as below while read x y do echo "$x $y" | grep "^#" > /dev/null 2>&1 [ $? -ne 0 ] && echo "${x}.sh $y" done < file.txt With both sed and while u will get the similar output. But while is timeconsuming and too many cmds involved. |
|
#5
|
||||
|
||||
|
Code:
#!/bin/ksh
while read x y
do
[[ "$x" != \#* ]] && echo "${x}.ksh ${y}"
done < file.txt
|
||||
| Google The UNIX and Linux Forums |