![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ignore some lines with specific words from file comparison | jakSun8 | Shell Programming and Scripting | 2 | 03-13-2008 12:11 AM |
| Reading a file and writing the file name to a param file. | thebeginer | UNIX for Advanced & Expert Users | 1 | 10-05-2007 04:38 PM |
| reading variables from a file | ttshell | Shell Programming and Scripting | 4 | 03-13-2006 11: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 05:25 AM |
| Reading a CSV file into shell variables problem | multidogzoomom | Shell Programming and Scripting | 6 | 10-11-2005 04:43 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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? |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|