![]() |
|
|
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 |
| How to convert byteArray variables to HexaString variables for Linux? | ritesh_163 | High Level Programming | 2 | 08-11-2008 12:55 AM |
| naming variables with variables | Allasso | Shell Programming and Scripting | 2 | 06-27-2008 11:45 AM |
| variables | DNAx86 | Shell Programming and Scripting | 3 | 04-17-2008 05:36 PM |
| Regarding PS1,PS2,PS3,PS4 variables. | anchal_khare | Shell Programming and Scripting | 5 | 02-04-2008 04:29 AM |
| Using sed with variables | Mark_A_Tritz | UNIX for Dummies Questions & Answers | 2 | 04-28-2004 09:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using sed with variables (again!)
Hi, I'm trying to use sed to delete the last three lines of a file. I currently have: Code:
# get the amount of lines in the file
foldernum=`wc -l File_In.txt | cut -c1-8`
# remove the lines in the file
sed "${foldernum}-3,${foldernum}d" File_In.txt > File_Out.txt
I get the error - sed: unknown command Is there a better way or have I simply got my syntax incorrect. Cheers. |
|
||||
|
I tried the code above but it didn't trim the last 3 lines of the file.
|
|
||||
|
You need to do the arithmetic separately, sed doesn't know how to subtract. awk does know; do you get an error message or does it just not do what you want? Maybe you need mawk/nawk/gawk/XPG4 awk if your default awk is a really old "traditional" awk. Code:
foldernum=`wc -l <File_In.txt` # note use of redirection limit=`expr $foldernum - 3` sed -e "$limit",'$d' File_In.txt >File_Out.txt |
|
||||
|
Quote:
However, I've played around with the code you provided and I got it to work accordingly. Thanks. |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|