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/newfilename.$DateTimeStamp;;
bjeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Doesn't look too bad, except for some mistakes.

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/$newfilename.$DateTimeStamp;;
              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/$newfilename.$DateTimeStamp;;
              esac
             done


wmp
0
bjeAuthor Commented:
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?
0
woolmilkporcCommented:
Yes.

newfilename=$(awk 'NR==4 {print $8}' $file)

"NR" is an automatic counter for "Number of Records" in awk.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

bjeAuthor Commented:
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
0
woolmilkporcCommented:
Use

awk -F"\t" 'NR== ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bjeAuthor Commented:
Thank you for all the help.  This is working great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.