Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove a line?

Status
Not open for further replies.

modfather

MIS
Feb 15, 2000
75
US
Hi. I need help! I should know how to do this, but I have a file that is actually a list of files acquired through frecover. The file looks like:

/
/user/filename.txt
/etc/password
/bin/command

What I want to do is remove the line that has JUST a "/" on it (the first line). Other lines have a "/" in them so I need to delete only the only line that has a "/" ONLY in it. I guess that would be a "/" followed by a CR/LF, right? I'd really rather do this with a unix shell script than perl.

Any help would be greatly appreciated!
Thanks.
Steve
 
Oh, one more thing:

I found another post on this site that said you could remove the last line of a file with:

$ sed '$d' original_file > file_without_last_l

which actually is close to what I want to do (in a way). The "/" line in my text file is actually always the first line. Can I delete the FIRST line? How?

Thanks.
Steve
 
cat ${FILE} | grep -v "^/$"

The caret represents the beginning of a line.
The dollar sign represents the end of a line.

So, ^/$ matches the beginning of a line, followed by a slash, followed by the end of the line.

-v reverses grep's matching to non-matching.
 
Hi:

This:


sed '1d' original_file

deletes the first line.

Ed
 
Or

sed '1d' original_file > file_without_first_line
CaKiwi
 
There is a million ways to skin a cat:
Code:
vi filename <<-EOF
1G
dd
ZZ
EOF
enjoy Einstein47
(&quot;For every expert, there is an equal and opposite expert.&quot; - Arthur C. Clarke)
 
Thanks for all the suggestions. I actually &quot;skinned this cat&quot; another way:

tail +2 filename > newfilename

How fun! :)

Thanks again!
Steve
 
uh jamisar,

The definition of the &quot;Right Way&quot; is &quot;the way that works, and that you understand.&quot;

I for one am happy that modfather found his/her own way to accomplish the task. To infer that there is only one &quot;right way&quot; in unix is akin to a god complex.


Are you really a programmer, or are you a manager? Einstein47
(&quot;For every expert, there is an equal and opposite expert.&quot; - Arthur C. Clarke)
 
Hi -

If the lone '/' is always on line 1 then

dd if=input of=output bs=1 skip=2 2>/dev/null

will skin the cat. How many lives are left on this kitty?

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top