简体   繁体   中英

Remove odd lines in a text file

File:

/home/USER/DIR/a
http://www.here.is.a.hyper.link.net/
/home/USER/DIR/b
http://www.here.is.another.hyper.link.net/

Need to remove all the odd lines in this file ( PUBLIC-DIRECTORY-LIST )? Its for my batch script which can be found below (dropbox batch puburl creator):

for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH
done > PUBLIC-DIRECTORY-LIST

Do I just append the command to prune PUBLIC-DIRECTORY-LIST at the end of the script?

# awk 'NR%2==0' file
http://www.here.is.a.hyper.link.net/
http://www.here.is.another.hyper.link.net/

我会使用awk,但那只是我:

awk '{if(i++%2)print}' foo.txt

For completeness here is the sed expression:

sed -e '1d;n;d' file

It is exactly as here except with an extra 1d command, this deletes the first line and so prints the odd lines instead of the even ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM