bje
asked on
pull a value from a tab delimited file
Hello,
I am working on pulling a value from a tab delimited file. Need to pull the value from the 8th tab position of a file, so it can be used as the file name for the file.
This is what I have,
FILELIST=`ls -1 2> /dev/null`
for file in $FILELIST
do
case $file in
WSC_862*.tsv ) newfilename = '$file | cut -d c -f8'
mv $file $destination_dir/newfilena me.$DateTi meStamp;;
I am working on pulling a value from a tab delimited file. Need to pull the value from the 8th tab position of a file, so it can be used as the file name for the file.
This is what I have,
FILELIST=`ls -1 2> /dev/null`
for file in $FILELIST
do
case $file in
WSC_862*.tsv ) newfilename = '$file | cut -d c -f8'
mv $file $destination_dir/newfilena
ASKER
Thank you
There are multiple lines in the files. Would need to look at the 4th line of the file and the values change. Can you Identified the 4th line without a unique value?
There are multiple lines in the files. Would need to look at the 4th line of the file and the values change. Can you Identified the 4th line without a unique value?
Yes.
newfilename=$(awk 'NR==4 {print $8}' $file)
"NR" is an automatic counter for "Number of Records" in awk.
newfilename=$(awk 'NR==4 {print $8}' $file)
"NR" is an automatic counter for "Number of Records" in awk.
ASKER
Thanks. This is working well, just one more question.
Does the print $8 count the spaces and tabs? In the file there are spaces and just need to count the number of tabs.
newfilename=$(awk 'NR==4 {print $8}' $file "tab value" )
Thanks for all the help
BJE
Does the print $8 count the spaces and tabs? In the file there are spaces and just need to count the number of tabs.
newfilename=$(awk 'NR==4 {print $8}' $file "tab value" )
Thanks for all the help
BJE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for all the help. This is working great.
Which line of the files do you want to pull the value from?
If there is only one line in each file this could work:
for file in $FILELIST
do
case $file in
WSC_862*.tsv ) newfilename=$(awk '{print $8}' $file)
mv $file $destination_dir/$newfilen
esac
done
If there is more than one line in the inputfile(s) you should have a unique criterion to select the appropriate line:
for file in $FILELIST
do
case $file in
WSC_862*.tsv ) newfilename=$(awk '/unique_search_string/ {print $8}' $file)
mv $file $destination_dir/$newfilen
esac
done
wmp