×
UNIX.COM Login
Username:
Password:  
Show Password






👤


Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Read input write multply output with creteria

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-13-2018
tonyk334 tonyk334 is offline
Registered User
 
Join Date: Mar 2018
Last Activity: 14 March 2018, 9:02 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Read input write multply output with creteria

Hi All

Please Help

Read input write multply output with creteria

Exemple i have file



Code:
abc 111 444
abc 111 444
def 111 444
def111 444
bbb 111 444
bbb 111 444

i would need write 3 files pos 1-3 is the Criteria

output would be file1 contains abc file2 def file3 bbb

Thank you

Last edited by vgersh99; 03-13-2018 at 12:37 PM.. Reason: code tags, please!
Sponsored Links
    #2  
Old 03-13-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 3:46 PM EDT
Location: Aachen, Germany
Posts: 13,062
Thanks: 447
Thanked 4,011 Times in 3,688 Posts
Did you consider the csplit command?

EDIT: Looking at your problem a secong time, csplit might NOT be the tool of choice. Try instead

Code:
awk '{TMP = substr ($0, 1, 3); if (!(TMP in FN)) FN[TMP] = ++CNT; print TMP  > ("file" FN[TMP])}' file


Last edited by RudiC; 03-13-2018 at 06:53 PM..
Sponsored Links
    #3  
Old 03-13-2018
tonyk334 tonyk334 is offline
Registered User
 
Join Date: Mar 2018
Last Activity: 14 March 2018, 9:02 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you

it will create 3 files?
    #4  
Old 03-14-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 3:46 PM EDT
Location: Aachen, Germany
Posts: 13,062
Thanks: 447
Thanked 4,011 Times in 3,688 Posts
It will create as many files as different criteria are present in the input file. Should these become more than ther OPEN_MAX system configuration parameter, append (>>) to the respective output files and close after each write.
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - read from a file and write conditional output mady135 Shell Programming and Scripting 3 11-21-2014 05:50 AM
Read input files and merge them in given order and write them to input one param or one file hyd1234 Shell Programming and Scripting 4 02-11-2014 10:59 AM
Read user input, Encrypt the data and write to file saichand1985 Shell Programming and Scripting 5 11-07-2012 04:29 AM
shell, read table and write the value for each factor to output @man Shell Programming and Scripting 9 10-26-2012 06:34 AM
read input-process-output cupid1575 Programming 5 10-11-2009 04:14 AM



All times are GMT -4. The time now is 10:08 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.