help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] split


From: Val Krem
Subject: [Help-bash] split
Date: Sat, 26 May 2018 17:28:05 +0000 (UTC)

Hi All,
I wanted to split a big file based on the value of the first column of thsi file
file 1 (atest.dat).1 ah1 251 ah2 26
4 ah5 354 ah6 362 ah2 54
I want to split this file into three files based on the first column 
 file 1 will be 
     1 ah1 25     1 ah2 26
file 2 would be    4 ah5 35    4 ah6 36
file three would be     2 ah2 54
The range of the first column could vary from 1 up to 100.
I trad  the following script 
################################################
#! bin/bash
numb=($(seq 1 1 10))
for i in "address@hidden"
   do
     awk '{if($1=='"${i}"') print $0}' atest.dat   > numb${i}.txt
   done
#################################################

The above script gave me 10  files while I was expecting only 3  files. 
How do I limit to get only the three files that do have data in atest.dat file?


Thank you





















reply via email to

[Prev in Thread] Current Thread [Next in Thread]