The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

2

A character (as seen in vi) may be the conversion from several possible encodings (utf8, ASCII, ISO8859-1, etc). Therefore, it is ambiguous when you declare: ...if I open the file with VI this is what I see: DESCRIPTION : test line 1ýtest line 2ýtest line 3 To remove ambiguity you should provide an hex (or octal) dump of the file contents. The command: ...


1

Yes, it can be done with a sed command. Remember to backup the file before making any changes to it. The backup can be removed after confirming that the results are correct or kept for later. As for the sed command, something like sed -i.backup -E 's/ i="([0-9]*)"/i\1/g' file should work (note that this will automatically make a backup of the original ...


1

Try tr '[a-z]' '[f-za-e]' There's an explanation from the inverse question at How does tr '[a-z]' '[n-za-m]' work?


0

awk 'BEGIN{ OFS=FS=":" } { if (NR==FNR) { pwd[$1]=$2 } else { if ($2 ~ /^!/ && $1 in pwd) $2=pwd[$1] print } }' shadowA shadowB When the first file shadowA is processed (NR==FNR), save the password hash in array pwd with the username as index. When the second file shadowB is processed (else) and the second field starts with a ! (...


0

You need to escape the $ before the $HOSTNAME variable (or $(hostname) command), so that it is expanded/run on the remote machine rather than the local machine: #!/bin/bash while read PASSWORD SERVER;do sshpass -p "$PASSWORD" ssh -t -p 1234 $SERVER << EOF wget -N https://example.com/file.conf 2>&1 | grep -i "failed\|error\|saved" sed -...


3

As a shell script: tempdir="$(mktemp -d)" i=0; for file in *.mp3; do i=$((i+1)) mv -- "$file" "$tempdir/${file%%[0-9]*.mp3}$(printf '%06d.mp3' "$i")" done mv "$tempdir"/* . && rmdir "$tempdir" Run this script in your mp3 directory. It will create a temporary directory and move renamed files to this dir to avoid renaming to filenames that ...


4

If you have perl-rename (called rename on Debian based systems, including Ubuntu), you can do: rename -n 's/\d+.mp3$/sprintf("%06d",$c++) . ".mp3"/e' *mp3 Explanation The -n causes rename to only print what it would do, without renaming anything. Remove it once you are sure the command does what you want. s/foo/bar/e : this is the substitution operator; ...


1

To skip the first two lines, you could use: sed '3,$s/=.*/=good/' file This does the substitution from line 3 to the last line ($).


1

Is this what you are looking for? With GNU sed. sed -E '/var[0-9]/!s/(=).*/\1good/' file


2

I think sed is the proper tool for what you want to do, here is my implementation - instead of looking for something, I negate what you are protecting: sed -r '/^((\$myvar1)|(\$myvar2))/!s/=.*$/="good"/g'


-1

Assuming you know ahead of time the variable names (e.g. $myname, $myage, and $mycity) that you would like to change, you can use sed: sed -i '/^\$myname=/s/=.*$/=good/g' input_file_name sed -i '/^\$myage=/s/=.*$/=good/g' input_file_name sed -i '/^\$mycity/s/=.*$/=good/g' input_file_name Basically, this just says to only run a regular expression on lines ...


Top 50 recent answers are included