Tag Info

New answers tagged

3

The better way to change the column separator and use columncommand: sed 's/ */;/g' file | column -ts';' which produce: Item Code Active Description Store Room Row Shelf Bin On Hand 38NUTZSL Y 3/8"-16 HEX ZINC NUT B 03 C 2 0 WELD-AL Y WELD, ALUM. ROD, ...


1

simulation.py: (output 10 lines every second) #!/usr/bin/env python import time i=0 while True: print("{} what up {}".format(i,i%10)) if i%10==9: time.sleep(1) i+=1 In one terminal: $ stdbuf -oL python simulation.py >> log.txt In another one: $ tail -f log.txt #10 new lines every second


1

You can use awk and set the field separator to either spaces or comma. Then, loop in blocks of 2, printing the first and second fields together with blocks of two: $ awk -v FS='(\\s+|,)' '{for (i=3; i<=NF; i+=2) print $1, $2, $i, $(i+1)}' file 3923 001 L05 LV 3923 001 L05 RM 3923 002 L12 RA 3923 002 L12 LA 3923 003 I06 ALL 3923 004 G04 RV 3923 004 Z09 ...


1

Simplyfied variant of User112638726 answer sed ':1;s/\(\(.*\s\s\+\)[^,]\+\),/\1\n\2/;t1' sed -r ':1;s/((.+\s\s+)[^,]+),/\1\n\2/;t1' will choice repeated part as «any symbols before 2(or more) spaces». Then you can pipe output through uniq -s 10


6

Given the format of your example this should work for any number of comma separated strings after the initial large space(if it's a tab just change the spaces in the second s/// to \t sed ':;h;s/,.*//;p;x;s/ [^,]*,/ /;t;d' file 3923 001 L05 LV 3923 001 L05 RM 3923 002 L12 RA 3923 002 L12 LA 3923 003 I06 ALL 3923 004 G04 RV 3923 ...


2

Possible solution with awk: awk -F" " '{ x = $3 " " $4 " " $5; split(x, a, ","); for (i in a) { print $1, $2 "\t" a[i]; } }' file Output should be: 3923 001 L05 LV 3923 001 L05 RM 3923 002 L12 RA 3923 002 L12 LA 3923 003 I06 ALL 3923 004 G04 RV 3923 004 Z09 ALL And if your input contains multiple , as in comments: 3923 001 L05 ...


3

It is possible using sed. Pipe the input to the below. | sed 's/\(^.\{12\}\)\([^,]\+\),\([^,]\+\)/\1\2\n\1\3/' output 3923 001 L05 LV 3923 001 L05 RM 3923 002 L12 RA 3923 002 L12 LA 3923 003 I06 ALL 3923 004 G04 RV 3923 004 Z09 ALL Here is the source to handle input with multiple "," For original input without tab, use | perl ...



Top 50 recent answers are included