Vi or Bash,way to delete everything but first N#lines
Ok so I have not idea how to do this and hope someone out there has a clue, what I need to be able to do is script a way to delete all BUT the first seven lines in a file, so everything below the seventh line is gone.
Anyone know any way of doing this? Any help is much appreciated :) |
Hi,
sed could do that: sed '1,7d' yourfile if you use a new sed you can use -i to change yourfile at once. |
Quote:
Something like this would do, Quote:
|
Code:
head -7 file |
Quote:
Sorry for that!!! |
Quote:
ssh <hostname> /usr/local/bin/sed -i '18,$d' /file/file Now I test it from <hostname> itself and the command works - but when I use ssh to run it I get this : /usr/local/bin/sed: -e expression #1, char 3: unexpected `,' Why would that be? |
You need to escape the $ in that line:
ssh <hostname> /usr/local/bin/sed -i '18,\$d' /file/file |
Quote:
ssh <hostname> /usr/local/bin/sed -i \'18\,\$d\' /file Works like a charm - Thanks for everyones help |
All times are GMT -5. The time now is 03:43 AM. |