Linux command line: split the line

I have a long file with the following list:

/drivers/isdn/hardware/eicon/message.c//add_b1()
/drivers/media/video/saa7134/saa7134-dvb.c//dvb_init()
/sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build()
/drivers/s390/char/tape_34xx.c//tape_34xx_unit_check()
(PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301()
/drivers/scsi/sg.c//sg_ioctl()
/fs/ntfs/file.c//ntfs_prepare_pages_for_non_resident_write()
/drivers/net/tg3.c//tg3_reset_hw()
/arch/cris/arch-v32/drivers/cryptocop.c//cryptocop_setup_dma_list()
/drivers/media/video/pvrusb2/pvrusb2-v4l2.c//pvr2_v4l2_do_ioctl()
/drivers/video/aty/atyfb_base.c//aty_init()
/block/compat_ioctl.c//compat_blkdev_driver_ioctl()
....

It contains all the functions in the kernel code. Designation file//function.

I want to copy several 100 files from the kernel directory to another directory, so I want to delete each line from the function name, leaving only the file name.

This is super-easy in python, any idea how to write a 1 liner at the bash prompt that does the trick?

Thanks,

Udi

+3
source share
3 answers
cat "func_list" | sed "s#//.*##" > "file_list"

Didn't run it :)

+9
source

You can use pure bash:

while read -r line; do echo "${line%//*}"; done < funclist.txt

Edit:

echo , sed : "//" , .

:

"echo ${line}" "echo $line"
"%" , ,
"%" , "%%" "//*" , "*" sed ". *"

. Bash man, :

  • ${parameter#word}
  • ${parameter/pattern/string} sed -
  • ${parameter:offset:length}
  • .
+6

(g) awk

awk -F"//" '{print $1}' file
+4

Source: https://habr.com/ru/post/1716326/


All Articles