Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a multiple sequence file as
>abc|d017961
sequence1......
>cdf|rhtdm9
sequence2......
>ijm|smthr12
sequence3......
>abc|d011wejr
sequence4......
>stg|eethwe77
sequence5......
I want to edit the file and want the result file as
>abc_ABC__d017961
sequence1......
>cdf_CDF__rhtdm9
sequence2......
>ijm_IJM__smthr12
sequence3......
>abc_ABC__d011wejr
sequence4......
>stg_STG__eethwe77
sequence5......
Thanks!
perl -pe 's/ (\w+) \| /$1_\U$1\E__/x' file
or
perl -lpe '$_ = "$1_\U$1\E__$2" if / (\w+) \| (\w+)/x' file
You can define the input field separator (FS) to be |, the output field separator (OFS) to be _ and then use the toupper() function.
All together:
$ awk 'BEGIN{OFS="_"; FS="\|"}{print $1,toupper($1),OFS,$2}' file
abc_ABC___d017961 sequence1......
cdf_CDF___rhtdm9 sequence2......
ijm_IJM___smthr12 sequence3......
abc_ABC___d011wejr sequence4......
stg_STG___eethwe77 sequence5......
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Can someone tell me what am I doing wrong here? It seems to work on my mac shell but does not work on linux box it seems. Looks like different version of awk? I want to make sure my code works on the linux version.
echo -e "${group_values_with_counts}" | awk '$1>='${value2}' { print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }'
21:19:41 awk: $1>= { print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }
21:19:41 awk: ^ syntax error
You're trying to pass the value of a shell variable into awk the wrong way and using a non-portable echo. The right way (assuming value2 doesn't contain any backslashes) is:
printf '%s\n' "$group_values_with_counts" |
awk -v value2="$value2" '$1>=value2{ print "{\"count\":\""$1"\",\"type\":\""$2"\"}" }'
If value2 can contains backslashes and you want them treated literally (e.g. you do not want \t converted to a tab character) then you need to pass it in using ENVIRON or ARGV. See http://cfajohnson.com/shell/cus-faq-2.html#Q24.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am novice,I want search a huge file using grep or regex which has list of Unique Id's.
Example file:
/icon_edit.png\" \/><\/a> AP-28992 : ABCD-1103_01 [v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/fax","<!-- 0000000000 --><a href=\"javascript:openTCEditWindow(0000,000);\"><img title=\"
TSD\" src=\"gui\/themes\/default\/images\/icon_edit.png\" \/><\/a> AP-28993 : ABCD-1103_02
[v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/traax","<!-- 0000000000 --> ABCD_110_01
Should be filtered uniquely below like:
ABCD-1103
ABCD-110
I guess ABCD-110 is your input pattern and space is delimiter
so if your input file viz. abc.txt is like (i have modified the last line)
$cat abc.txt
/icon_edit.png\" \/><\/a> AP-28992 : ABCD-1103_01 [v1]","2","2012-10-27
18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/fax","<!-- 0000000000 --><a
href=\"javascript:openTCEditWindow(0000,000);\"><img title=\"
TSD\" src=\"gui\/themes\/default\/images\/icon_edit.png\" \/><\/a> AP-28993 :
ABCD-1103_02
[v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/traax","<!-- 0000000000 --> ABCD-110_01
Then the following works:
$cat abc.txt | grep -ow "ABCD-110.*" | awk '{print $1}'
ABCD-1103_01
ABCD-1103_02
ABCD-110_01
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working on redHat linux.
I've a file which looks like :
$vi filename
Jan,1,00:00:01,someone checked your file
Jan,3,09:38:02,applebee
Jan,16,10:20:03, ****************
Jan,18,03:04:03, ***************
I want the output to look like:
2015/01/01,00:00:01,someone checked your file
2015/01/03,3,09:38:02,applebee
2015/01/16,16,10:20:03, ****************
2015/01/18,03:04:03, ***************
Please help me to do this. Thanks
If you have GNU date, try:
$ awk -F, '{cmd="date -d \""$1" "$2"\" +%Y/%m/%d"; cmd|getline d; print d","$3","$4; close(cmd)}' file
2015/01/01,00:00:01,someone checked your file
2015/01/03,09:38:02,applebee
2015/01/16,10:20:03, ****************
2015/01/18,03:04:03, ***************
This approach cannot be used with the BSD (OSX) version of date because it does not support any comparable -d option.
How it works
awk implicitly loops over lines of input, breaking each line into fields.
-F,
This tells awk to use a comma as the field separator
cmd="date -d \""$1" "$2"\" +%Y/%m/%d"
This creates a string variable, cmd, and contains a date command. I am assuming that you have GNU date.
cmd|getline d
This runs the command and captures the output in variable d.
print d","$3","$4
This prints the output that you asked for.
close(cmd)
This closes the command.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm trying to replace a string in a filename:
Original filename:
gamename games.com.zip
Target filename:
gamename.zip
I'm trying to replace the string games.com with an empty string. gamename is not a constant string it can be anything, but games.com is a constant string.
I'd use
mv "$filename" "${filename/ games.com/}"
This is documented under 'Pattern subsitution' in the 'Bash' man-page
Or http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion online
Bash parameter expansion will help:
mv "$f" "${f/ games.com}"
Try the following rename command:
$ filename="gamename games.com.zip"
$ rename " games.com" "" "$filename"
Since the name of your zip file has a space you need to make sure you enclose it in double-quotes.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am facing a problem to convert a document that has the following:
This author {john, #99} said that ...
... bla bla this other author mentioned {barlic, #1508} ...
I would like that vim convert it to :
This author \cite{latexref99} said that ...
... bla bla this other author mentioned \cite{latexref1508} ...
Any idea how to do that ? but also how to revert to :
This author {,#99} said that ... ... bla bla this other author mentioned {, #1508} ..
Convert to:
:%s/{[^#]*#\(\d\+\)}/\\cite{latexref\1}/g
Convert back:
:%s/\\cite{latexref\(\d\+\)}/{,#\1}/g
you dont need a plugin you can use sed:
sed -e 's/{[^}]*\#\([0-9]*\)}/\\cite\{latexref\1\}/g' < file.tex >new_ref.tex
you also can map this to a shortcut in vim
nmap n :%w ! cat % \| sed -e 's/{[^}]*\#\([0-9]*\)}/\\cite\{latexref\1\}/g' > % <CR>