LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-04-2011, 11:13 AM   #1
shawn.k
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
AWK: Placing Splitted files into a Specific directory


Hello,

With the help of http://www.linuxquestions.org/questi...ng-awk-824408/ I was able to write a awk oneliner to split a file into multiple files based on a column.

Code:
awk -F"|" ' { print $2 > "TEST_"$1".csv" } ' ABC.csv
This script works perfectly in splitting the file. I want one additional functionality added to this script on placing the resultant into a specific directory.

Source:

/home/Src/ABC.csv

Target:

/home/Res/csv/TEST_1.csv
/home/Res/csv/TEST_2.csv
/home/Res/csv/TEST_3.csv
/home/Res/csv/TEST_4.csv

I'm not sure how to add path to above script. Any help is greatly appreiciated.

Thanks
 
Old 10-04-2011, 10:47 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
The expectations in this are that the target path is a exactly as you've shown it, and is to a directory that exists before running the awk program. Then this should work:


Code:
awk -F"|" ' { print $2 > "/home/Res/csv/TEST_"$1".csv" } ' ABC.csv
 
1 members found this post helpful.
Old 10-05-2011, 05:01 PM   #3
shawn.k
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kakaka View Post
The expectations in this are that the target path is a exactly as you've shown it, and is to a directory that exists before running the awk program. Then this should work:


Code:
awk -F"|" ' { print $2 > "/home/Res/csv/TEST_"$1".csv" } ' ABC.csv
Thank you very much it worked.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
use Awk to isolate a specific directory level... AndrewJS Linux - Newbie 13 09-04-2011 10:35 AM
Joining splitted files oogje Linux - Software 2 04-09-2008 10:26 AM
Compare files in specific directory to files on CD szim90 Linux - Newbie 3 02-10-2007 08:39 PM
Remove ALL files from specific Directory bianchi Programming 9 11-23-2005 11:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration