Converting and reverting in VIM the endnote {author , #XXX} references? [closed] - vim

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>

Related

AWK command not working in linux but works in mac [closed]

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.

Changing the date format in a file [closed]

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.

Shell variable is being treated as command [closed]

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 7 years ago.
Improve this question
I have written this small script to compare file name with the files in one folder and copy them to another folder if they do not exist in the first one. Please refer code. But for some reason Ubuntu 15.04 is treating my variable as command and giving me following error:
./COPY_FILES.sh: line 8: FILE_EXIST_IN_SUPER_STRING: command not found
while read NAME1
do
FILE_EXIST_IN_SUPER_STRING = 0
while read NAME2
do
if [ "$NAME1" == "$NAME2" ]
then
FILE_EXIST_IN_SUPER_STRING = 1
fi
done < file_superstring.txt
if [ "$FILE_EXIST_IN_SUPER_STRING" == 0 ]
then
cp Master/"$NAME1" Non-SuperString/"$NAME1"
fi
done < Total_files.txt
Third line should have no spaces.
It should be:
FILE_EXIST_IN_SUPER_STRING=0

Parsing the headers of sequence file [closed]

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......

How to replace a string in a filename [closed]

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.

Resources