sed command to remove the first field from a '|' delimited file

Hi
I have a file with fields delimited by |. I need to remove the first field from the file. I tried cut but it just extracts that field.

sample.output
abc|100|name1
cde|200|name2
efg|300|name3

Output should be
sample.output
100|name1
200|name2
300|name3

thanks
Var

sed -i 's/^[^|]*|//' input.txt

The cut does work:

cut -d'|' -f2- Input_File

Thank you Shell_Life and Mirni..
Mirni
For sed i am getting error when i use -i option

> sed -i 's/^[^|]*|//' FINAL.output
sed: illegal option -- i
Usage: sed [-n] [-e script] [-f source_file] [file...]

But i was able to use by redirecting it

sed 's/^[^|]*|//' FINAL.output > FINAL.output.new

But i dont want to create a temporary file. Do we have any option to edit within the same file.
Shell_life
Thanks, I was using wrong option. Is it possible to redirect the output to same file?

Thanks
Var

Well, that's what -i (in-place edit) of sed does. If your version of sed doesn't support it, then temporary file can be used, just like you did. You could do without, with a (rather obscure) construct:

{ rm input.txt && sed 's/^[^|]*|//' > input.txt; } < input.txt

Same thing with cut

{ rm input.txt && sed 's/^[^|]*|//' > input.txt; } < input.txt

Or, using a subshell instead of a block:

( rm input.txt && sed 's/^[^|]*|//' > input.txt ) < input.txt

But, in my opinion, these are quite artificial, and it's much more clear doing:

sed 's/^[^|]*|//' input.txt > input.txt.tmp && mv input.txt.tmp input.txt

Please use code tags when posting code and/or sample in/output.

ed can save the day! :slight_smile:

printf %s\\n '1,$s/^[^|]*|//' w q | ed -s file

or using a heredoc

ed -s file <<'EOED'
1,$s/^[^|]*|//
w
q
EOED

---------- Post updated at 05:25 PM ---------- Previous update was at 05:21 PM ----------

I'm curious. Why not?

Regards,
Alister