0

I want to remove the headers of a file and replace its content without headers in the same file.

Example: file_student

name age
XYS 24
RTF 56

The output should be:

XYS 24
RTF 56

The scenario is that I do not want to create any new file for this change. Can sed do this?

I tried:

sed 1d /tmp/file_student.txt |
hadoop fs -copyfromLocal /tmp/file_student.txt /tmp/file_student_no_header.txt

But that does not work. Any help is appreciated!

joeytwiddle
  • 29,306
  • 13
  • 121
  • 110
Neethu Lalitha
  • 3,031
  • 4
  • 35
  • 60

2 Answers2

0

an extract from sed's man page

-i[SUFFIX]' --in-place[=SUFFIX]' This option specifies that files are to be edited in-place. GNU `sed' does this by creating a temporary file and sending output to this file rather than to the standard output.(1).

 This option implies `-s'.

 When the end of the file is reached, the temporary file is renamed
 to the output file's original name.  The extension, if supplied,
 is used to modify the name of the old file before renaming the
 temporary file, thereby making a backup copy(2)).

 This rule is followed: if the extension doesn't contain a `*',
 then it is appended to the end of the current filename as a
 suffix; if the extension does contain one or more `*' characters,
 then _each_ asterisk is replaced with the current filename.  This
 allows you to add a prefix to the backup file, instead of (or in
 addition to) a suffix, or even to place backup copies of the
 original files into another directory (provided the directory
 already exists).

 If no extension is supplied, the original file is overwritten
 without making a backup.

so you need to change your sed command to sth like sed -i 1d file | whatever hope this helps.

Marc Bredt
  • 905
  • 5
  • 13
0

If you don't want to use sed, try tail - e.g. you have a file called xxx:

tail -n +2 xxx > xxx.tmp && mv xxx.tmp xxx

smcstewart
  • 2,016
  • 14
  • 16