awk concat lines between 2 sequent digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk concat lines between 2 sequent digits
# 8  
Old 10-26-2011
[QUOTE=ctsgnb;302567989]
Code:
awk '!f&&/[0-9]+/{if(!c++){r=$0;printf $0}else{if($0-r==1){r=$0;printf "\n" r}else{f=1}};next}!f{printf FS $0}END{print}' RS=" "

This is exactly what I was looking for, but:

Code:
awk '!f&&/^[0-9]+/{if(!c++){r=$0;printf  $0}else{if($0-r==1){r=$0;printf "\n" r}else{f=1}};next}!f{printf FS  $0}END{print}' RS=" "

# 9  
Old 10-26-2011
Code:
awk 'BEGIN{RS=""}{for (i=1;i<=NF;i++) printf ($i~/^[0-9]+$/)?ORS $i:FS $i}' infile |awk -vVMIN=99 -vVMAX=102 '$1>=VMUN&&$1<=VMAX'

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

Put in one line only the lines with digits

Hello, I haven't been here for a while and I might be forgetting some things. I have an input text like this titleA http://myurl/bla/blabla/1234 http://myurl/bla/blabla/6789 titleB http://myurl/bla/blabla/5678 http://myurl/bla/blabla/1234 titleC http://myurl/bla/blabla/9123... (10 Replies)
Discussion started by: Kibou
10 Replies

3. Shell Programming and Scripting

Concat String with variable after a 'grep' and awk

Here is the structure of my file: MyFile.txt g-4.n.g.fr 10.147.243.63 g-4.n.g.fr-w1 Here is my sript: test.sh #! /bin/sh ip=10.147.243.63 worker=$(grep -e $ip $1 | awk '{ print $3; }') echo "" echo $worker echo "" echo $worker echo "" echo "$worker.v.1" echo... (7 Replies)
Discussion started by: chercheur111
7 Replies

4. UNIX for Dummies Questions & Answers

concat any two lines in a file

I have a file with line 4 : F SITE SPA_M2 SPA_M3 SPA_M4 and a line 237 with: BV_N4 VbdGO_PW Rs_NW_STI Rc_N+OD need a awk liner to concat the two lines so that line 2 sits next to line1 and looks like: F SITE SPA_M2 SPA_M3 SPA_M4 BV_N4 VbdGO_PW ... (8 Replies)
Discussion started by: awkaddict
8 Replies

5. Shell Programming and Scripting

Need help in concat of two lines in a file

Hi , Need help in concating two lines based on certain character, for example my file has the messages : :57A:qweqweww :58A:qeqewqeqe -}$ {1:fffff2232323}{2:123123dasds}{4: :20:121323232323232 :21:sdsadasdasddadad if the line ends with "-}$" or if a line starts with "{1:" then it... (5 Replies)
Discussion started by: ulin
5 Replies

6. Shell Programming and Scripting

Awk Concat

Hi All this may be somewhere in internet , but couldnt find the it. i have file as abc01 2010-07-01 12:45:24 2010-07-01 12:54:35 abc02 2010-07-01 12:59:24 2010-07-01 01:05:13 abc03 . . . the output using awk should look like this abc01|2010-07-01 12:45:24|2010-07-01 12:54:35... (3 Replies)
Discussion started by: posner
3 Replies

7. Shell Programming and Scripting

How to concat lines that have the same key field

Hi, I have file like this - ABC 123 ABC 456 ABC 321 CDE 789 CDE 345 FGH 111 FGH 222 FGH 333 XYZ 678 I need the output like this: ABC 123,456 CDE 789,345 FGH 111, 222 XYZ 678 Meaning I want to concat the lines that have the same first column, but I only need the first two... (10 Replies)
Discussion started by: redwing
10 Replies

8. Shell Programming and Scripting

Conditional concat lines awk

Hello, I have a text file like this: NONE FILE_Rename frompath: /log_audit/AIX/log/current/AIXAFTPP.log NONE FILE_Unlink filename /audit/tempfile.14041142 NONE FILE_Rename ... (8 Replies)
Discussion started by: carloskl
8 Replies

9. Shell Programming and Scripting

concat 6 files in 1 file ( maybe use AWK?)

hi, I have the following problem: - 6 different files that have one key in common. - this six files must be aggregated in one output file sorted by the key. - the main file has to be writen twice, one in the beggining of the new output file and another in the end, for each key. - add one... (3 Replies)
Discussion started by: naoseionome
3 Replies

10. UNIX for Dummies Questions & Answers

mailx on sequent

Hi I am working on sequent unix. I would like to use the "mailx -c" (for the purpose of corbon copy). But I got error illigal option. I tried with tilda c (~c). but this works only from command line. Is there any way that I can use this from shellscript. I have looked in to our database... (1 Reply)
Discussion started by: reddyb
1 Replies
Login or Register to Ask a Question