1

I have a few questions:

I have listed the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain using

$ wc -l /group/book/four/word/*|sort -n

...and I got:

2 /group/book/four/word/wer.txt
2 /group/book/four/word/rti.txt
3 /group/book/four/word/cool.txt

This is what I wanted! Perfect.

But now I want to make the list generated contain ONLY the file names, e.g like this

wer.txt
rti.txt
cool.txt

How can I do that using the "od" command?

And how can I use "sed" to remove the numbers at the start of the line of the results I got above? How can I do the same but only for the first two lines?

1
  • 3
    You should not mix completely different questions. Delete the shell part and make it a separate question. Dec 17, 2014 at 23:42

2 Answers 2

0

You get the list of files with pathname expansion:

cd /group/book/four/word
echo *
# or into a file
echo * >/path/to/filelist.txt

You can delete everything in a line from the start up to (including) the first space (or group of spaces) with this sed command:

sed 's/^[^ ]  *//g'

I don't see what od has to do with that.

sed can be limited to the first two lines e.g. by having it exit on the third line:

sed -e 3d -e 's/^[^ ]  *//g'
0

I would throw sed in directly after sort and have it write out the files as you want them all in one go:

wc -l /group/book/four/word/*|sort -n | 
sed 'w ./not_as_yet_touched.txt
 1,2s/^[0-9 ]*//w ./first_two_lines_without_line_numbers_or_leading_spaces.txt
    s|.*/||w ./everything_up_to_first_slash_trimmed.txt'

As written, sed will still autoprint the results of running all of the above commands, but the results shown on the terminal (or wherever stdout goes) will only faithfully reflect the contents of the last file. The other two are written at different times during sed's line cycle and so their contents will differ.

About od though... hmmm... od doesn't really delimit data so much as it does dump it. You might use od in combination with another filter (such as sed) to clear out the portions of the line as you ask, but without a specific and regular byte count between / characters, you probably won't have much use for it. Of course, the final command up there should handle that anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .