![]() |
|
|
|
|
|||||||
| 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 |
| Exec explanation needed | myle | UNIX for Dummies Questions & Answers | 3 | 04-05-2008 04:23 PM |
| SED command ---------help needed | veerapureddy | Shell Programming and Scripting | 4 | 03-17-2008 02:12 PM |
| help needed in ls command | anju | Shell Programming and Scripting | 1 | 02-18-2008 04:20 AM |
| Help needed for ps command in AIX | moe2266 | AIX | 0 | 09-30-2005 08:43 AM |
| help needed for sed command | manualvin | UNIX for Dummies Questions & Answers | 2 | 06-24-2004 08:41 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
sed command explanation needed
Hi,
Could you please explain me the below statement -- phrase wise. sed -e :a -e '$q;N;'$cnt',$D;ba' abc.txt > xyz.txt if suppose $cnt contains value: 10 it copies last 9 lines of abc.txt to xyz.txt why it is copying last 9 rather than 10. and also what is ba and $D over there in command. reply me as early as possible. Thanks, Subbu |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
A more lisible format of the command (with variable substitition made)
Code:
sed -e ' :a $q N 10,$D ba ' abc.txt > xyz.txt (0):label Marks a branch point to be referenced by the b and t subcommands. This label can be any sequence of eight or fewer bytes. Defines label a $q (1)q Branches to the end of the script. It does not start a new cycle. $ means last line of input. If last line of input, print the line and stop processing. N (2)N Appends the next line of input to the pattern space with an embedded new-line character (the current line number changes). You can use this to search for patterns that are split onto two lines. 10,$D (2)D Deletes the initial segment of the pattern space through the first new-line character and then starts the next cycle. From line 10 to end, removes the oldest line (added by N command) at the begining of the buffer. So the buffer contains all time at most 9 lines. ba (2)b[label] Branches to the : command bearing the label variable. If the label variable is empty, it branches to the end of the script. Branch to label a The command is equivalant to : Code:
tail -f 9 abc.txt > xyz.txt Jean-Pierre. |
|
#3
|
|||
|
|||
|
Hi Jean-Pierre,
Thank you very much for your quick response. Is this correct way to copy all the lines of abc.txt, except the first line to xyz.txt using sed command as following.... cnt=`cat abc.txt | wc -l` sed -e :a -e '$q;N;'$cnt',$D;ba' abc.txt > xyz.txt or, is there any effective way of doing this using sed command? Pls, give me solution using sed command only. Thanks, Subbu. |
|
#4
|
||||
|
||||
|
The simplest manner, erases the first line and prints the others
Code:
sed -e '1d' abc.txt > xyz.txt Jean-Pierre. |
|
#5
|
|||
|
|||
|
Hi
Hi Jean-Pierre,
why I have asked you only sed command is .... I don't want to use tail command (it's truncating some part of data as it handles in only 20 k buffer). Let me know any other options available except tail. Thank you very much, Subbu. |
|||
| Google The UNIX and Linux Forums |