Help text manipulation


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
Help text manipulation

Hello Forum ,
I need a help about text manupulation. I have a text file and I have to manipulate this file. Let's say source.txt

Code:
source.txt
UNB+UNOC:3+O0013000005MAN MN  RVS:91+0098006688:92+190304:2313+F004169241'
UNH+8146848+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234101+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JM:AT'
LOC+54+F28022::92'
LIN+++33.25480-5827:IN'
IMD+F++:::WIAZKA ELEKTRYCZNA  LADEN-HAST E4C-'
QTY+131:1:C62'
UNT+17+8146848'
UNH+8146849+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234102+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JN:AT'
LOC+54+F28023::92'
LIN+++PZ.25480-5758:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
UNT+17+8146849'
UNH+8146851+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234103+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JQ:AT'
LOC+54+F28026::92'
LIN+++PZ.25480-5756:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5769:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5798:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5810:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
UNT+26+8146851'
UNZ+3+F004169241'

Code:
cat -n source.txt
1  UNB+UNOC:3+O0013000005MAN MN  RVS:91+0098006688:92+190304:2313+F004169241'
     2  UNH+8146848+DELJIT:D:96A:UN'
     3  BGM+307:::JIS_SYNCRO_FIRM+2019030423234101+9'
     4  DTM+137:20190304:102'
     5  DTM+67:201902140600:203'
     6  RFF+AOW:90000032'
     7  NAD+ST+F::92'
     8  LOC+7+F-MOKB::92'
     9  LOC+11+WARENEINGANG::92'
    10  LOC+159+FJ0010::92'
    11  SEQ+39+628601:4'
    12  DTM+94:201902141041:203'
    13  GIR+4+0012C-0294:AN++JM:AT'
    14  LOC+54+F28022::92'
    15  LIN+++33.25480-5827:IN'
    16  IMD+F++:::WIAZKA ELEKTRYCZNA  LADEN-HAST E4C-'
    17  QTY+131:1:C62'
    18  UNT+17+8146848'
    19  UNH+8146849+DELJIT:D:96A:UN'
    20  BGM+307:::JIS_SYNCRO_FIRM+2019030423234102+9'
    21  DTM+137:20190304:102'
    22  DTM+67:201902140600:203'
    23  RFF+AOW:90000032'
    24  NAD+ST+F::92'
    25  LOC+7+F-MOKB::92'
    26  LOC+11+WARENEINGANG::92'
    27  LOC+159+FJ0010::92'
    28  SEQ+39+628601:4'
    29  DTM+94:201902141041:203'
    30  GIR+4+0012C-0294:AN++JN:AT'
    31  LOC+54+F28023::92'
    32  LIN+++PZ.25480-5758:IN'
    33  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    34  QTY+131:1:C62'
    35  UNT+17+8146849'
    36  UNH+8146851+DELJIT:D:96A:UN'
    37  BGM+307:::JIS_SYNCRO_FIRM+2019030423234103+9'
    38  DTM+137:20190304:102'
    39  DTM+67:201902140600:203'
    40  RFF+AOW:90000032'
    41  NAD+ST+F::92'
    42  LOC+7+F-MOKB::92'
    43  LOC+11+WARENEINGANG::92'
    44  LOC+159+FJ0010::92'
    45  SEQ+39+628601:4'
    46  DTM+94:201902141041:203'
    47  GIR+4+0012C-0294:AN++JQ:AT'
    48  LOC+54+F28026::92'
    49  LIN+++PZ.25480-5756:IN'
    50  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    51  QTY+131:1:C62'
    52  LIN+++PZ.25480-5769:IN'
    53  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    54  QTY+131:1:C62'
    55  LIN+++PZ.25480-5798:IN'
    56  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    57  QTY+131:1:C62'
    58  LIN+++PZ.25480-5810:IN'
    59  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    60  QTY+131:1:C62'
    61  UNT+26+8146851'
    62  UNZ+3+F004169241'

I am interest in the records of between every "GIR" lines
Code:
catn -n source.txt|grep -i "GIR"

    13  GIR+4+0012C-0294:AN++JM:AT'
    30  GIR+4+0012C-0294:AN++JN:AT'
    47  GIR+4+0012C-0294:AN++JQ:AT'

SO My final output will be;

Code:
GIR+4+0012C-0294:AN++JM:AT' LIN+++33.25480-5827:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT' LIN+++PZ.25480-5758:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5756:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5769:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5798:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5810:IN' QTY+131:1:C62'

I need LIN & QTY lines for each GIR lines. As above first GIR line starts at the line of 13 so through the second GIR (at line 40) There are lines LIN & QTY. I want to write out as GIR_NAME LIN QTY.

--- Post updated at 09:29 AM ---

Code:
source.txt
UNB+UNOC:3+O0013000005MAN MN  RVS:91+0098006688:92+190304:2313+F004169241'
UNH+8146848+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234101+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JM:AT'
LOC+54+F28022::92'
LIN+++33.25480-5827:IN'
IMD+F++:::WIAZKA ELEKTRYCZNA  LADEN-HAST E4C-'
QTY+131:1:C62'
UNT+17+8146848'
UNH+8146849+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234102+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JN:AT'
LOC+54+F28023::92'
LIN+++PZ.25480-5758:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
UNT+17+8146849'
UNH+8146851+DELJIT:D:96A:UN'
BGM+307:::JIS_SYNCRO_FIRM+2019030423234103+9'
DTM+137:20190304:102'
DTM+67:201902140600:203'
RFF+AOW:90000032'
NAD+ST+F::92'
LOC+7+F-MOKB::92'
LOC+11+WARENEINGANG::92'
LOC+159+FJ0010::92'
SEQ+39+628601:4'
DTM+94:201902141041:203'
GIR+4+0012C-0294:AN++JQ:AT'
LOC+54+F28026::92'
LIN+++PZ.25480-5756:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5769:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5798:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
LIN+++PZ.25480-5810:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
UNT+26+8146851'
UNZ+3+F004169241'

Code:
cat -n source.txt
1  UNB+UNOC:3+O0013000005MAN MN  RVS:91+0098006688:92+190304:2313+F004169241'
     2  UNH+8146848+DELJIT:D:96A:UN'
     3  BGM+307:::JIS_SYNCRO_FIRM+2019030423234101+9'
     4  DTM+137:20190304:102'
     5  DTM+67:201902140600:203'
     6  RFF+AOW:90000032'
     7  NAD+ST+F::92'
     8  LOC+7+F-MOKB::92'
     9  LOC+11+WARENEINGANG::92'
    10  LOC+159+FJ0010::92'
    11  SEQ+39+628601:4'
    12  DTM+94:201902141041:203'
    13  GIR+4+0012C-0294:AN++JM:AT'
    14  LOC+54+F28022::92'
    15  LIN+++33.25480-5827:IN'
    16  IMD+F++:::WIAZKA ELEKTRYCZNA  LADEN-HAST E4C-'
    17  QTY+131:1:C62'
    18  UNT+17+8146848'
    19  UNH+8146849+DELJIT:D:96A:UN'
    20  BGM+307:::JIS_SYNCRO_FIRM+2019030423234102+9'
    21  DTM+137:20190304:102'
    22  DTM+67:201902140600:203'
    23  RFF+AOW:90000032'
    24  NAD+ST+F::92'
    25  LOC+7+F-MOKB::92'
    26  LOC+11+WARENEINGANG::92'
    27  LOC+159+FJ0010::92'
    28  SEQ+39+628601:4'
    29  DTM+94:201902141041:203'
    30  GIR+4+0012C-0294:AN++JN:AT'
    31  LOC+54+F28023::92'
    32  LIN+++PZ.25480-5758:IN'
    33  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    34  QTY+131:1:C62'
    35  UNT+17+8146849'
    36  UNH+8146851+DELJIT:D:96A:UN'
    37  BGM+307:::JIS_SYNCRO_FIRM+2019030423234103+9'
    38  DTM+137:20190304:102'
    39  DTM+67:201902140600:203'
    40  RFF+AOW:90000032'
    41  NAD+ST+F::92'
    42  LOC+7+F-MOKB::92'
    43  LOC+11+WARENEINGANG::92'
    44  LOC+159+FJ0010::92'
    45  SEQ+39+628601:4'
    46  DTM+94:201902141041:203'
    47  GIR+4+0012C-0294:AN++JQ:AT'
    48  LOC+54+F28026::92'
    49  LIN+++PZ.25480-5756:IN'
    50  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    51  QTY+131:1:C62'
    52  LIN+++PZ.25480-5769:IN'
    53  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    54  QTY+131:1:C62'
    55  LIN+++PZ.25480-5798:IN'
    56  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    57  QTY+131:1:C62'
    58  LIN+++PZ.25480-5810:IN'
    59  IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
    60  QTY+131:1:C62'
    61  UNT+26+8146851'
    62  UNZ+3+F004169241'

Code:
catn -n source.txt|grep -i "GIR"

    13  GIR+4+0012C-0294:AN++JM:AT'
    30  GIR+4+0012C-0294:AN++JN:AT'
    47  GIR+4+0012C-0294:AN++JQ:AT

Code:
GIR+4+0012C-0294:AN++JM:AT' LIN+++33.25480-5827:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT' LIN+++PZ.25480-5758:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5756:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5769:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5798:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5810:IN' QTY+131:1:C62'

# 2  
Old 1 Week Ago
Dear cemokam65 ,

You are not using code tags correctly and we (the admins and moderators) are required to edit and fix your posts.

Code tags are written like this:

[CODE} blab blah blah [/CODE]

Not as you were doing:

[CODE} blab blah blah [CODE/]

Please be careful when posting.

Thanks.
# 4  
Old 1 Week Ago
Code:
awk '/GIR/,/QTY/' source.txt>t_source.txt

Code:
more t_source.txt
GIR+4+0012C-0294:AN++JM:AT'
LOC+54+F28022::92'
LIN+++33.25480-5827:IN'
IMD+F++:::WIAZKA ELEKTRYCZNA  LADEN-HAST E4C-'
QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT'
LOC+54+F28023::92'
LIN+++PZ.25480-5758:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT'
LOC+54+F28026::92'
LIN+++PZ.25480-5756:IN'
IMD+F++:::CZESC PROTOTYPOWA  EL-LEITUNGSSATZ'
QTY+131:1:C62'

And finaly;
Code:
cat t_source.txt|grep -v IMD|grep -v LOC>f_source.txt

Code:
more f_source.txt

Code:
GIR+4+0012C-0294:AN++JM:AT'
LIN+++33.25480-5827:IN'
QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT'
LIN+++PZ.25480-5758:IN'
QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT'
LIN+++PZ.25480-5756:IN'
QTY+131:1:C62'

Now I need to get ifnal output like as ;
Code:
GIR+4+0012C-0294:AN++JM:AT' LIN+++33.25480-5827:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT' LIN+++PZ.25480-5758:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5756:IN' QTY+131:1:C62'

# 5  
Old 1 Week Ago
Your own approach could be condensed and then complemented like
Code:
awk '/GIR/,/QTY/' file | grep -v "IMD\|LOC" | paste -sd"  \n"
GIR+4+0012C-0294:AN++JM:AT' LIN+++33.25480-5827:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT' LIN+++PZ.25480-5758:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5756:IN' QTY+131:1:C62'

but would not necessarily yield the desired result. How about
Code:
awk '/^GIR/ {GN = $0}; /^LIN/ {LN = $0} /^QTY/ {print GN, LN, $0}' file
GIR+4+0012C-0294:AN++JM:AT' LIN+++33.25480-5827:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JN:AT' LIN+++PZ.25480-5758:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5756:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5769:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5798:IN' QTY+131:1:C62'
GIR+4+0012C-0294:AN++JQ:AT' LIN+++PZ.25480-5810:IN' QTY+131:1:C62'


Last edited by RudiC; 1 Week Ago at 05:58 AM..
This User Gave Thanks to RudiC For This Post:
cemokam65 (1 Week Ago)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Text Manipulation Help galford UNIX for Beginners Questions & Answers 4 04-11-2016 03:41 PM
Text manipulation suppliernr1 UNIX for Dummies Questions & Answers 3 02-02-2015 09:14 AM
Text manipulation help galford UNIX for Dummies Questions & Answers 7 09-14-2014 02:49 PM
Text manipulation help galford UNIX for Dummies Questions & Answers 1 11-12-2011 07:36 PM
text manipulation help galford UNIX for Dummies Questions & Answers 4 10-17-2011 10:27 AM
text manipulation help galford UNIX for Dummies Questions & Answers 5 10-14-2011 09:31 AM
Text Manipulation Help galford UNIX for Dummies Questions & Answers 1 09-29-2011 03:24 PM
text manipulation help galford UNIX for Dummies Questions & Answers 3 09-20-2011 04:16 PM
Text Manipulation Help galford Shell Programming and Scripting 7 09-09-2011 10:06 AM
[HELP] Text manipulation... [HELP] slutb3 Shell Programming and Scripting 5 07-18-2011 06:24 AM
Text Manipulation vanesa1230 UNIX for Dummies Questions & Answers 2 04-30-2010 10:11 PM
Help with text manipulation dustinwang2003 UNIX for Dummies Questions & Answers 2 03-07-2009 08:02 AM
text manipulation rajkishore UNIX for Dummies Questions & Answers 6 03-06-2009 04:30 AM
text manipulation injeti Shell Programming and Scripting 11 06-05-2008 10:42 AM
Text Manipulation. Icepick Shell Programming and Scripting 4 02-25-2008 03:18 AM