Reputation: 305
I need to delete ""
in file
"CITFFUSKD-E0"
I have tried sed 's/\"//
.
Result is:
CITFFUSKD-E0"
How I can delete both ?
Also I need to delete everything behind first word but input can be this one:
"CITFFUSKD-E0"
"CITFFUSKD_E0"
"CITFFUSKD E0"
Result I want it:
CITFFUSKD
Upvotes: 0
Views: 115
Reputation: 2794
Many legitimate ways to solve this.
I favor using what you know about your data to simplify solutions -- this is usually an option. If everything in your file follows the same pattern, you can simply extract the first set of capitalized letters encountered:
sed 's/"\([A-Z]\+\).*$/\1/' file
Upvotes: 0
Reputation: 20022
When you have 1 line, you can use
grep -Eo "(\w)*" file | head -1
For normal files (starting with a double quote on each line) , try this
tr -c [^[:alnum:]] '"' < file | cut -d'"' -f2
Upvotes: 0
Reputation: 627190
You may use
sed 's/"//g' file | sed 's/[^[:alnum:]].*//' > newfile
Or, contract the two sed
commands into one sed
call as @Wiimm suggests:
sed 's/"//g;s/[^[:alnum:]].*//' file > newfile
If you want to replace inline, see sed edit file in place.
Explanation:
sed 's/"//g' file
- removes all "
chars from the filesed 's/[^[:alnum:]].*//' > newfile
- also removes all chars from a line starting from the first non-alphanumeric char and saves the result into a newfile
.Upvotes: 1
Reputation: 41460
This should do all in one go, remove the "
, print the first part:
awk -F\" '{split($2,a,"-| |_");print a[1]}' file
CITFFUSKD
CITFFUSKD
CITFFUSKD
Upvotes: 0
Reputation: 141583
delete everything behind first word
sed 's/^"\([[:alpha:]]*\)[^[:alpha:]]*.*/\1/'
Match the first "
. Then match a sequence of alphabetic characters. Match until you find non-alphabetic character ^[:alpha:]
. Then match the rest. Substitute it all for \1
- it is a backreference for the part inside \( ... \)
, ie. the first word.
I need delete two “ ” with sed command
Remove all possible "
:
sed 's/"//g'
Extract the string between "
:
sed 's/"\([^"]*\)"/\1/'
Remove everything except alphanumeric characters (numbers + a-z + a-Z, ie. [0-9a-zA-z]
):
sed 's/[^[:alnum:]]//g'
Upvotes: 0
Reputation: 133680
Could you please try following.
awk 'match($0,/[a-zA-Z]+[^a-zA-Z]*/){val=substr($0,RSTART,RLENGTH);gsub(/[^a-zA-Z]+/,"",val);print val}' Input_file
Upvotes: 0