0

I have one of these files.

There are numbers on the first line, alphabets on the second line, special characters on the third line.

This repeats itself. What I mean is the first line is number the second line is alphabet the third line is special character the fourth line is number the fifth line is alphabet 6th line is special character and repeated again and again and again. I want to pull out the lines with the alphabet and redirect them to another file.

I know how to redirect. And here's the command I know.(I think this can be a hint....)

sed -n '1 ~ 2p' file name (output all odd lines) and sed -n '1 ~ 2! p' (output all even lines)

I really wonder how to do this.

Also, I'm curious about the command to draw only lines with numbers and special characters. Well

The command which you can use is the above two commands. (I'm curious to use sed)

I really want to know.

0

You want search for Alpha characters ?
SED is better for stream editing, here is a simpler search method

grep -E '[a-zA-Z]' infile > outfile

And next, if you want all but Alpha, write this

grep -E '[^a-zA-Z]' infile > outfile

BUT IF YOU WANT TO USE SED to remove all but Second line, do this

sed -n 'n;p;n' infile
0

The GNU sed n~m can be read as n skip m. So given a file like:

1234
abcd
#$^*
5678
zxcv
)&*%
96401
YnayI
+}\[_

then to print only the first, third, fourth, sixth and so on you can delete 2 skip 3:

$ sed '2~3d' file
1234
#$^*
5678
)&*%
96401
+}\[_

Less efficiently, you could print 1 and 3, with skips of 3 in both cases:

$ sed -n -e '1~3p' -e '3~3p' file
1234
#$^*
5678
)&*%
96401
+}\[_

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.