I have a file where all the column headers are the path names. I want to abbreviate each column header from something that looks like:
/mydir/cat/dog/hen/test/block/sample1.so.rg.mk.bam /mydir/cat/dog/hen/test/block/sample2.so.rg.mk.bam
to:
sample1 sample2
How do I do this in linux? My files have anywhere from 46 to 100+ columns so manually editing column names is not an option. My desired file names are each 7 characters in length, as above.
Thanks
The header has the filename. Each column header/ name is
/mydir/cat/dog/hen/test/block/sample1.so.rg.mk.bam
where I just want it to be
sample1
To clarify, this is one text file with 46 columns. Each column header or name appears as the lengthy string above and I want to truncate each header to the 7 character version, e.g. 'sample1'...'sampl46'
Desired Example file (with data under each column header)
sample1 sample2 sample3 sample4 sample5 ...
basename /mydir/cat/dog/hen/test/block/sample1.so.rg.mk.bam | sed 's/\.[[:alnum:]]\+//g'
sample1
...sample46...
that gets abbreviated tosampl46
in order to get it down to 7 characters, or does the input start with...sampl46...
?