0

Need here command which removes any data at left side of ; (semicolon) on each following row:

07:48;1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
08:00;1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
08:16;1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
08:32;1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
08:48;1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
09:00;1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
09:16;1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
09:32;1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
09:48;1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
10:00;1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
10:16;1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
10:32;1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,

In some way that it would results in rows as follows:

1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,

Would it be please in GNU awk, egrep or sed?

15

Another sed variant:

sed 's/^[^;]*;//' file

Replace any non-semicolon characters ([^;]*) at the beginning of the line (the first ^) followed by a semicolon with an empty string.

35

This is what the cut command is for.

cut -d';' -f2-
  • 1
    Since there are only two columns, you could omit trailing -. – Cyrus Oct 19 at 4:46
  • 1
    Good point Cyrus made - although for OP I would suggest it is left in for some scalability, ie if they add more data delimited by semicolons, they don't need to modify the script. – QuickishFM Oct 19 at 11:11
  • 1
    +1. While the accepted answer works, I feel that in general this answer is less complicated to understand and should have been the accepted answer instead. I also agree on @QuickishFM that the trailing - helps for accidental second semicolons per line or if the worked-on data expands on more than just two fields to still get the remainder of the line. – Phoenix Oct 20 at 8:03
  • 1
    Perhaps an explanation would be nice. +1 though. This is the simple answer. – Tommiie Oct 20 at 20:08
9

In awk:

awk 'BEGIN { FS = ";" } ; { print $2 }' 

or, even simpler

awk -F";" '{print $2}'

(thank you, ilkkachu, for this simplified version)

  • 2
    awk -F";" '{print $2}' is the same but shorter – ilkkachu Oct 19 at 10:39
  • thank you. I will add this to the answer. – karlsebal Oct 19 at 12:58
6

With GNU sed:

sed -E 's/^.*;(.*)/\1/' file

With GNU grep:

grep -Po '(?!.*;).*' file 
6
< inputfile egrep ';' | cut -f 2 -d ';'

-This command and you will get this!

  • 2
    I recommend testing it. – Cyrus Oct 19 at 4:43
  • 1
    @Cyrus, if you were referring to the minor issue with that misplaced filename, you might as well have mentioned it straight up, or edited to fix it... – ilkkachu Oct 19 at 13:06
5

There are, as the existing answers already show, many ways to do this. Here's another GNU grep approach:

$ grep -oP ';\K.*' file
1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,

The -o makes grep print only the matching portion of the line and the -P enables Perl Compatible Regular Expressions. PCRE has \K which means "ignore anything matched before". Putting all that together, the command will find the first ;, discard it and then print the rest of the line.

Another option is to use perl in its awk-mode (-a):

$ perl -F';' -lane 'print $F[1]' file
1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,

Or use perl like sed and delete everything up to the first ;:

$ perl -pe 's/.*?;//' file
1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,
  • "awl-mode-perl" to emulate cut -d\; -f2- is '$, = ";"; print @F[1..$#F]' – glenn jackman Oct 21 at 14:48
4

Considering that this input is Data01.txt, it may be done as:

awk -F";" '{ print $2 }' Data01.txt > Data01\ Ready.txt

Which will output Data01 Ready.txt file.

2

Python for fun, now.

python -c "import sys; [print(line.strip().split(';')[1]) for line in sys.stdin]" < input_file.txt

1563101282.M178569P409830.de122.abteilung.com,S=1258,W=1287:2,
1563102004.M49870P436474.de122.abteilung.com,S=1258,W=1287:2,
1563102961.M195946P457876.de122.abteilung.com,S=1258,W=1287:2,
1563103921.M334168P463856.de122.abteilung.com,S=1258,W=1287:2,
1563104883.M883187P502037.de122.abteilung.com,S=1258,W=1287:2,
1563105603.M799240P519637.de122.abteilung.com,S=1258,W=1287:2,
1563106561.M419884P547969.de122.abteilung.com,S=1258,W=1287:2,
1563107524.M145768P582635.de122.abteilung.com,S=1258,W=1287:2,
1563108483.M632493P607265.de122.abteilung.com,S=1258,W=1287:2,
1563109203.M675460P633790.de122.abteilung.com,S=1258,W=1287:2,
1563110163.M299406P663234.de122.abteilung.com,S=1258,W=1287:2,
1563111121.M682713P685072.de122.abteilung.com,S=1258,W=1287:2,

Because print adds a newline, you either have to remove it with end='' or strip out the newline from the file with .strip(). Both work fine; I chose the latter here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.