Delete string file after space

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have many log files generated like the bellow:
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
I want to delete the String Armani but my command is not working:
cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log
I'm following the next post
Is the another way to make it?
PS. There are strings in the same field with different length.
text-processing awk sed
add a comment |Â
up vote
1
down vote
favorite
I have many log files generated like the bellow:
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
I want to delete the String Armani but my command is not working:
cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log
I'm following the next post
Is the another way to make it?
PS. There are strings in the same field with different length.
text-processing awk sed
1
Why did you addgrep identifierto your pipeline?
â Jesse_b
Aug 8 at 21:53
1
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next;delimiter that can be as simple assed 's/ [^;]*//' file.log
â steeldriver
Aug 8 at 21:56
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have many log files generated like the bellow:
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
I want to delete the String Armani but my command is not working:
cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log
I'm following the next post
Is the another way to make it?
PS. There are strings in the same field with different length.
text-processing awk sed
I have many log files generated like the bellow:
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
I want to delete the String Armani but my command is not working:
cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log
I'm following the next post
Is the another way to make it?
PS. There are strings in the same field with different length.
text-processing awk sed
text-processing awk sed
edited Aug 8 at 22:15
Jesse_b
10.5k22659
10.5k22659
asked Aug 8 at 21:51
Mareyes
13611
13611
1
Why did you addgrep identifierto your pipeline?
â Jesse_b
Aug 8 at 21:53
1
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next;delimiter that can be as simple assed 's/ [^;]*//' file.log
â steeldriver
Aug 8 at 21:56
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13
add a comment |Â
1
Why did you addgrep identifierto your pipeline?
â Jesse_b
Aug 8 at 21:53
1
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next;delimiter that can be as simple assed 's/ [^;]*//' file.log
â steeldriver
Aug 8 at 21:56
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13
1
1
Why did you add
grep identifier to your pipeline?â Jesse_b
Aug 8 at 21:53
Why did you add
grep identifier to your pipeline?â Jesse_b
Aug 8 at 21:53
1
1
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next
; delimiter that can be as simple as sed 's/ [^;]*//' file.logâ steeldriver
Aug 8 at 21:56
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next
; delimiter that can be as simple as sed 's/ [^;]*//' file.logâ steeldriver
Aug 8 at 21:56
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
Using awk:
awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
This will split the 4th column by whitespace and then set it to the first element.
Should work regardless of what is in the 4th column:
$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere
$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
add a comment |Â
up vote
1
down vote
To delete the text 'Armani' from the file, use this:
$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
To edit it inplace:
$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'
add a comment |Â
up vote
1
down vote
The cat is pointless so that can go.
Identifier is not in your sample input so let's assume you meant blabla.
Your request to delete the users last name seems completely unrelated to your example command so let's just change that
grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log
If that does not give you what you want you should rewrite your question so that it is clear.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Using awk:
awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
This will split the 4th column by whitespace and then set it to the first element.
Should work regardless of what is in the 4th column:
$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere
$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
add a comment |Â
up vote
1
down vote
accepted
Using awk:
awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
This will split the 4th column by whitespace and then set it to the first element.
Should work regardless of what is in the 4th column:
$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere
$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Using awk:
awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
This will split the 4th column by whitespace and then set it to the first element.
Should work regardless of what is in the 4th column:
$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere
$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere
Using awk:
awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
This will split the 4th column by whitespace and then set it to the first element.
Should work regardless of what is in the 4th column:
$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere
$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere
edited Aug 8 at 22:19
answered Aug 8 at 22:00
Jesse_b
10.5k22659
10.5k22659
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
add a comment |Â
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
â Mareyes
Aug 9 at 0:34
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
fname is just a variable to hold the split string (In this case I was thinking first name)
â Jesse_b
Aug 9 at 0:40
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
â Mareyes
Aug 9 at 0:55
add a comment |Â
up vote
1
down vote
To delete the text 'Armani' from the file, use this:
$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
To edit it inplace:
$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'
add a comment |Â
up vote
1
down vote
To delete the text 'Armani' from the file, use this:
$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
To edit it inplace:
$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'
add a comment |Â
up vote
1
down vote
up vote
1
down vote
To delete the text 'Armani' from the file, use this:
$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
To edit it inplace:
$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'
To delete the text 'Armani' from the file, use this:
$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
To edit it inplace:
$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$
If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'
answered Aug 8 at 21:55
steve
12.9k22149
12.9k22149
add a comment |Â
add a comment |Â
up vote
1
down vote
The cat is pointless so that can go.
Identifier is not in your sample input so let's assume you meant blabla.
Your request to delete the users last name seems completely unrelated to your example command so let's just change that
grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log
If that does not give you what you want you should rewrite your question so that it is clear.
add a comment |Â
up vote
1
down vote
The cat is pointless so that can go.
Identifier is not in your sample input so let's assume you meant blabla.
Your request to delete the users last name seems completely unrelated to your example command so let's just change that
grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log
If that does not give you what you want you should rewrite your question so that it is clear.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The cat is pointless so that can go.
Identifier is not in your sample input so let's assume you meant blabla.
Your request to delete the users last name seems completely unrelated to your example command so let's just change that
grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log
If that does not give you what you want you should rewrite your question so that it is clear.
The cat is pointless so that can go.
Identifier is not in your sample input so let's assume you meant blabla.
Your request to delete the users last name seems completely unrelated to your example command so let's just change that
grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log
If that does not give you what you want you should rewrite your question so that it is clear.
edited Aug 8 at 22:18
answered Aug 8 at 21:58
user1133275
2,277412
2,277412
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461376%2fdelete-string-file-after-space%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Why did you add
grep identifierto your pipeline?â Jesse_b
Aug 8 at 21:53
1
None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next
;delimiter that can be as simple assed 's/ [^;]*//' file.logâ steeldriver
Aug 8 at 21:56
@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
â Mareyes
Aug 8 at 21:59
@Mareyes: I don't see the string "identifier" in your sample input at all
â Jesse_b
Aug 8 at 22:06
@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
â Mareyes
Aug 9 at 0:13