Sponsored Content
Full Discussion: Split file using awk
Top Forums UNIX for Beginners Questions & Answers Split file using awk Post 303022255 by rosebud123 on Wednesday 29th of August 2018 12:02:17 AM
Old 08-29-2018
Thanks.

I adjusted the script as below

Code:
#!/usr/bin/ksh
PAR1=$1
PAR2=$2
PAR3=$3

awk '{y=substr($2,1,4); f=b} y<lt{f=a} y>gt{f=c} {print>f} ' lt="${PAR1}" gt="${PAR2}" a=y1 b=y2 c=y3 $PAR3

Few more adjustments I need to make.
  1. How to append input filename portion to the resulting files y1,y2,y3

    Example : Input FileName = abc_123~xyz

    Desired Output FileName = abc_y1_123~xyz
  1. At this point I do not whether it would be coulum 2 that I have to check , instead of including column 2 can I just go by position on the substr ?

    Example :

    Code:
    awk '{y=substr($0,1,4); f=b} y<lt{f=a} y>gt{f=c} {print>f} ' lt="${PAR1}" gt="${PAR2}" a=y1 b=y2 c=y3 $PAR3


Please advise on the above...Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split file using awk

I am trying to read a file and split the file into multiple files. I need to create new files with different set of lines from the original file. ie, the first output file may contain 10 lines and the second 100 lines and so on. The criteria is to get the lines between two lines starting with some... (8 Replies)
Discussion started by: pvar
8 Replies

2. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

3. Shell Programming and Scripting

split file with awk

I did a lot of search on this forum on spiting file; found a lot, but my requirement is a bit different, please guide. Master file: x:start:5 line1:23 line2:12 2:90 x:end:5 x:start:2 45:56 22:90 x:end:2 x:start:3 line1:23 line2:12 x:end:3 x:start:2 line5:23 (1 Reply)
Discussion started by: uwork72
1 Replies

4. Shell Programming and Scripting

awk - split file

How can I split a text file (in awk) in n others with number of record given in input? Thanks (6 Replies)
Discussion started by: pinguc
6 Replies

5. Shell Programming and Scripting

split a file using awk

Hi , I just need to split a file and outputfiles are redirected to gzip file need: Input file - A.gz content of A.gz is 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200212|sdfdf 100|sfdds|dffdds|200212|sdfdf... (3 Replies)
Discussion started by: mohan_xunil
3 Replies

6. Shell Programming and Scripting

How to split a file using AWK?

Hello, I have a file like the following: david,a,b,c,20,r thomas,a,b,c,30,r willaiam,a,b,c,80,r barbara,a,b,c,100,r I would like to split the file into other files using a condition for the contents of column 5. The condition should be a if the contents of column 5 is in a range... (4 Replies)
Discussion started by: keenboy100
4 Replies

7. Shell Programming and Scripting

AWK File Split

Hi All, Input.txt XYZONEABC                  CZXTWOJJJ KKKSIXOOO asdfhajlsdhfajs asdfasfasdf Output Files: ONE.txt XYZONEABC                 TWO.txt CZXTWOJJJ SIX.txt KKKSIXOOO I had a script (2 Replies)
Discussion started by: kmsekhar
2 Replies

8. Shell Programming and Scripting

Split a file with awk

Hi! I have a file like this: a,b,c,12,d,e a,b,c,13,d,e a,b,c,14,d,e a,b,c,15,d,e a,b,c,16,d,e a,b,c,17,d,e I need to split that file in two: If field 4 is equal or higher than 14 that row goes to one file and if it is equal or higher than 15 to another. Can anyone point me in the... (2 Replies)
Discussion started by: Tr0cken
2 Replies

9. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

10. Shell Programming and Scripting

awk file split

Hi all, First of all I' like to mention that I'm pretty new to unix scripting. :( I'm trying to split an large xml with awk and rename it based on the values of two attributes. Example XML <RECORD> <element1>11</element1> <element2>22</element2> <element3>33</element3>... (18 Replies)
Discussion started by: f0usk4s
18 Replies
RESCAN-SCSI-BUS.SH(8)					      System Manager's Manual					     RESCAN-SCSI-BUS.SH(8)

NAME
rescan-scsi-bus.sh - rescan the SCSI bus. SYNOPSIS
rescan-scsi-bus.sh [ -l ] [ -w ] [ -c ] [ -r ] [ host... ] DESCRIPTION
rescan-scsi-bus.sh is a program that is used to rescan the SCSI bus using the SCSI add-single-device feature of the Linux SCSI layer. OPTIONS
-l Activates scanning for LUNs 0 .. 7 (default: 0). -L NUM Activates scanning for LUNs 0 .. LUN (default: 0). --luns=LIST Scan only LUNs in LIST. -w Enables scanning for device IDs 0 .. 15 (default: 0 .. 7). --ids=LIST Scan only device IDs in LIST. -i, --issue-lip Issue a FibreChannel LIP reset (default: disabled). -r, --remove Enables removing of devices (default: disabled). --forceremove Remove and readd every device (dangerous). -c Enables scanning of channels 0 1 (default: 0). --channels=LIST Scan only channels in LIST. host, --hosts=LIST If host adapters are given, only these are scanned (default: all). --nooptscan Don't stop looking for LUNs if 0 is not found. --color Use coloured prefixes OLD/NEW/DEL. LIST is a comma separated list of single values and ranges (no spaces allowed), e.g. 0,2-3,8,10-15. AUTHOR
rescan-scsi-bus.sh was written by Kurt Garloff <garloff@suse.de>. COPYRIGHT
This program is free software. You can use it under the terms of the GNU GPL (General Public License) Version 2 (or any later version, at your option). Note, that the GNU GPL implies, that there is NO WARRANTY at all. Full text of the GPL can be found in /usr/share/common- licenses/GPL file. AVAILABILITY
rescan-scsi-bus.sh is available from http://www.garloff.de/kurt/linux/scsidev/ March 1998 RESCAN-SCSI-BUS.SH(8)
All times are GMT -4. The time now is 06:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy