The delete the 2th
to delete from 2th
but if I want to delete 2th 3th 4th
or
but if I want to delete 2th 15th
how could I do?
Your request is extremely vague. What do you mean by?:
Quote:
but if I want to delete 2th 3th 4th
Do you want to delete the 2nd, 3rd, and 4th lines in the file?
Do you want to delete the 2nd, 3rd, and 4th fields in each line in the file?
What is in the lines other than unaccented uppercase letters and unaccented lowercase letters? If the fields are separated from each other by one or more space or tab characters do you also want the space and tab characters following the fields that are being removed to be removed or do you want to leave the separators unchanged?
Do you want to only print lines that have been changed, or do you want to every line after the changes have been completed. (Your current code appears to want to print unchanged lines once and changed lines twice.)
According to the standard, the use of 2g in
produces undefined results.
You can specify a count or the g flag, but not both.
Since you don't show us any of your input, you don't give us the output from the commands you listed, and you don't show us the output you want to get from a representative input file, any suggestions you get here will be wild conjecture as to whether or not you will get anything resembling what you want.
With the sed commands you are showing, I assume that you are trying to remove fields rather than lines, that you want to leave any field separators unchanged, and that you want to every line in the file once. In that case, something like:
will delete two or more letters in the 2nd, 3rd, 4th, and 14th nonadjacent occurrences of adjacent letters from every line. If a line has fewer occurrences of this condition, it will still make changes to any of the times the request is matched. If the input file (9) contains:
the output will be:
---------- Post updated at 07:35 AM ---------- Previous update was at 07:32 AM ----------
Quote:
Originally Posted by Don Cragun
Your request is extremely vague. What do you mean by?:
Do you want to delete the 2nd, 3rd, and 4th lines in the file?
Do you want to delete the 2nd, 3rd, and 4th fields in each line in the file?
What is in the lines other than unaccented uppercase letters and unaccented lowercase letters? If the fields are separated from each other by one or more space or tab characters do you also want the space and tab characters following the fields that are being removed to be removed or do you want to leave the separators unchanged?
Do you want to only print lines that have been changed, or do you want to every line after the changes have been completed. (Your current code appears to want to print unchanged lines once and changed lines twice.)
According to the standard, the use of 2g in
produces undefined results.
You can specify a count or the g flag, but not both.
Since you don't show us any of your input, you don't give us the output from the commands you listed, and you don't show us the output you want to get from a representative input file, any suggestions you get here will be wild conjecture as to whether or not you will get anything resembling what you want.
With the sed commands you are showing, I assume that you are trying to remove fields rather than lines, that you want to leave any field separators unchanged, and that you want to every line in the file once. In that case, something like:
will delete two or more letters in the 2nd, 3rd, 4th, and 14th nonadjacent occurrences of adjacent letters from every line. If a line has fewer occurrences of this condition, it will still make changes to any of the times the request is matched. If the input file (9) contains:
the output will be:
I want to delete the 2nd, 3rd, and 4th fields in each line in the file, can we use one line sed to handle this?
To delete the 2nd, 3rd, and 4th fields (using the same assumptions I made above about what you define a field to be), the following single line sed will handle it:
it is just harder to read than the same code with the <semicolon>s replaced by <newline>s. It can't be done with a single sed substitute command. (At least it can't in a portable way. Some implementations of sed might support providing a list and/or range of values when specifying which occurrence of a match for the BRE in a substitute command, but I haven't seen any that do so.
The person who started this thread still hasn't told us what the input format is. This one line will remove the 2nd, 3rd, and 4th fields if and only if there are no characters other than spaces and unaccented alphabetic characters in the before the end of the 4th string of letters ends.
The submitter also asked how to delete the 2nd and 15th fields. That can still be done as a single replacement but it is tedious to type and debug at best.
We need a CLEAR statement of what a field is from the submitter before any of us will know if what we might suggest will work.
My script will take the input file:
where {tab} is a tab character and produce:
With the same input, your script will just copy the input to the output without change. I have no idea which if either of these is what the submitter wants since there is no definition of what is in the file other than some alphabetic characters.
input
"A","B","C,D","E","F"
"S","T","U,V","W","X"
"AA","BB","CC,DD","EEEE","FFF"
required output:
"A","B","C,D","C,D","F"
"S", T","U,V","U,V","X"
"AA","BB","CC,DD","CC,DD","FFF"
tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
I am trying to use sed to delete the ^M at the end of the line and when i pass a file './asciiFix.sh wintest.txt' I get an error saying sed: can't read : no such file or dir. Can someone give me a pointer as to what I am doing wrong?
#!/bin/sh
if file "$@" | grep "with CRLF"; then
echo... (5 Replies)
I am not able to analyze the below code..
What I expected is that DELETED will be replaced with the first field in every line.But after giving a try, the output was different.
Can anyone pleas analyze and explain the code in detail?
Many thanks...
$ sed 's/* /DELETED /g' g1.txt > g4.txt... (2 Replies)
I have tried doing this to delete some lines: sed '1,10d' file
Now I want to specify a variable as a line number for example:
lastline=wc -l file
linestart=$lastline - 20
sed '$linestart,$lastlined' file
but this will give error: sed: -e expression #1, char 3: extra characters after... (4 Replies)
Hi,
I have a text file with content as follows:
bla foo3200492
comment on this: 3900302
here comes the teddy 12
all I need is:
3200492
3900302
12
So I need the correct "sed" command to delete everything until the first number.
I am not a regex expert, because I have to... (3 Replies)
Hi All,
I am very new to UNIX...
I was trying to delete ^ from a file and save it with different name...
The version is AIX 5.3
The input file is in this directory /a/b
The Input file name is o9876.out
I want the output file in same path with different name like ABC.txt... (5 Replies)
Hi,
I have two files test1,test2. If the number in test1 file exist in test2 then i want to remove that from test2 file.
Ex:
File- test1
12
13
14
15
==============
File- test2
1A~12
2B~13
3C~33
4D~22
I want to remove row which contains 12,13 from test2. I am using this sed... (2 Replies)