Sponsored Content
Top Forums Shell Programming and Scripting Generate files from one file based on lines Post 302746743 by Don Cragun on Thursday 20th of December 2012 01:21:43 AM
Old 12-20-2012
Quote:
Originally Posted by itkamaraj
In the below line, why it was not considered as 94 ?

Code:
 
94yr 48yr  4hr  erhj  reh

---------- Post updated at 11:34 AM ---------- Previous update was at 11:31 AM ----------

Code:
 
$ nawk '{a=substr($1,1,2)+0;sub("^[0-9]","",$0)}a<=9||a>12{print >> "first.txt"}a==1||a>=10&&a<=12{sub("^[0-9]","",$0);print >>"second.txt"}' a.txt
 
$ cat first.txt
ABC 13478 aqjerh 473 343   
hej 478 5775 24578 23892
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 738 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
DEF 136578 aqjrh 43 33   
htr 478 5775 24578 2392
fhd fg 847 brjkb f99345 487
eh ehjk 84 47589 8947 234
784 487 78 52895 8975
 57489 eghe9 4575 859479 
fnbd 4y5 4iuy  458 h irh
fjdg 74  7845 8475 5789 
4yr 48yr  4hr  erhj  reh
 
$ cat second.txt 
ABC 13478 aqjerh 473 343   
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe 
DEF 136578 aqjrh 43 33   
fh g 874 fr b8457 hjk 
hgf fej efjg j ghjegf 
hj fjg jfeg feg gjgwe

Hi itkamaraj,
If you look back at message #1 in this thread, you'll see that the line you asked about is shown as:
Code:
94yr 48yr  4hr  erhj  reh

rather than
Code:
94yr 48yr  4hr  erhj  reh

(the 9 is in red, but the 4 is in black).

I assumed that the intent was that the numbers in red are line numbers (in repeating sets numbered from 1 through 12) used for discussion, but not actually present in the input file. Your code sample assumes that these numbers in red actually appear in the file.

i150371485 needs to clarify the intent for us to find out which assumption was correct.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting lines from a delimited files based on a 2nd file

I need a little help... I have a file with 3 fields, Time/Date, IP address, UniqueID I have a 2nd file of UniqueIDs. I want to either (which ever is easier): 1. delete entries in file 1 that have a UniqueID in file 2 2. create a new file with the fields from File 1, excluding the... (4 Replies)
Discussion started by: goldie363
4 Replies

2. Shell Programming and Scripting

Adding lines to files based on file extension

I have posted this before but did not get many replies, so here it goes again. I have several files name like this If the file extension is 1a, I woould like to add at the beggining of the file the following sequence If the file extension is 1b, thn the entry that should be added is the next... (2 Replies)
Discussion started by: Xterra
2 Replies

3. Shell Programming and Scripting

generate report based on data in files.

Hi All, I need to develop a shell script which does sanity check of a data file, as below. 1. For DATE columns, it should check if date is given in proper format or not? For example, if format of date is expected as DD-MON-YYYY HH24:MI:SS and we received the date in formation like DDMMYYYY HH24,... (1 Reply)
Discussion started by: ace_friends22
1 Replies

4. Shell Programming and Scripting

How to generate a csv files by separating the values from the input file based on position?

Hi All, I need help for doing the following. I have a input file like: aaaaaaaaaabbbbbbbbbbbbbbbbbbbb cccbbbbbaaaaaadddddaaaabbbbbbb now I am trying to generate a output csv file where i will have for e.g. 0-3 chars of each line as the first column in the csv, 4-10 chars of the line as... (3 Replies)
Discussion started by: babom
3 Replies

5. Shell Programming and Scripting

Generate zone files based off subnet

Hi, I'm attempting to generate zone files based off the subnet address of a reverse zone. For example... My text file contains the following.. 5.4.7.0/24 5.4.7.0/24 68.74.23.0/24 68.74.24.0/24 I want to create a separate file for each of the listed blocks. Each file should contain... (1 Reply)
Discussion started by: spartan22
1 Replies

6. Shell Programming and Scripting

compare 2 files and return unique lines in each file (based on condition)

hi my problem is little complicated one. i have 2 files which appear like this file 1 abbsss:aa:22:34:as akl abc 1234 mkilll:as:ss:23:qs asc abc 0987 mlopii:cd:wq:24:as asd abc 7866 file2 lkoaa:as:24:32:sa alk abc 3245 lkmo:as:34:43:qs qsa abc 0987 kloia:ds:45:56:sa acq abc 7805 i... (5 Replies)
Discussion started by: anurupa777
5 Replies

7. Shell Programming and Scripting

Extracting lines from text files in folder based on the numbers in another file

Hello, I have a file ff.txt that looks as follows *ABNA.txt 356 24 36 112 *AC24.txt 457 458 321 2 ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Discussion started by: mohamad
2 Replies

8. Shell Programming and Scripting

Delete specific lines from files based on another file

I have some text files in a folder named ff as follows. I need to delete the lines (in-place editing)in these files based on another file aa.txt. 32bm.txt: 249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9 250... (2 Replies)
Discussion started by: aden
2 Replies

9. UNIX for Beginners Questions & Answers

Split file into multiple files based on empty lines

I am using below code to split files based on blank lines but it does not work. awk 'BEGIN{i=0}{RS="";}{x="F"++i;}{print > x;}' Your help would be highly appreciated find attachment of sample.txt file (2 Replies)
Discussion started by: imranrasheedamu
2 Replies

10. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 05:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy