delete last character of filenames in a folder [closed] - sed

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a folder that contains some text files. I need to delete the last character of each filename in this folder. filenames are shown below.
1ADFG.txt
RG25A.txt
5SDFC.txt
Desired output
1ADF.txt
RG25.txt
5SDF.txt

I would do like this:
for i in *.txt; do echo "mv '$i' '${i/?.txt}.txt'"; done
If the output looks good, then pipe it to | sh, that is:
for i in *.txt; do echo "mv '$i' '${i/?.txt}.txt'"; done | sh

This
awk 'BEGIN {FS="."} {print substr($1,1,length($1)-1) "." $2;}'
feeded with the list of the names should do the job, provided that there's only 1 dot, the one for the extension.

You could also use sed like this :
$ ls -1
1ADFG.txt
5SDFC.txt
RG25A.txt
$ ls -1|sed "s/\([A-Za-z0-9]\{4\}\)[A-Za-z0-9]*\(\.[A-Za-z0-9]\)/\1\2/g"
1ADF.txt
5SDF.txt
RG25.txt

another way is to use the perl rename utility:
$ rename -n 's/.\./\./' *.txt
1ADFG.txt renamed as 1ADF.txt
5SDFC.txt renamed as 5SDF.txt
RG25A.txt renamed as RG25.txt

Related

Modify print job with one liner - missing output command [closed]

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 2 years ago.
Improve this question
I am using Perl with our printing output system. Usually we call perl scripts, but I am just replacing a keyword with another word. In a console and a test file this worked with this one liner:
perl -pi -e "s/KEYWORD1/KEYWORD2"
Now I wanted to use it with our system and it gives me the error that there is no output file created. As I am fairly new to the field of Perl and want to have it used within a one liner, how can i do this?
Thank you very much for your help.
Kind regards
As Shawn mentioned in the comment, you are missing / in the substitution command s///. You are also missing a filename, which is needed for the -i option.
Both of these fail and print a warning and an error:
perl -pi -e "s/KEYWORD1/KEYWORD2" < foo
# or:
cat foo | perl -pi -e "s/KEYWORD1/KEYWORD2"
They print messages:
-i used with no filenames on the command line, reading from STDIN.
Substitution replacement not terminated at -e line 1.
Correct usage:
perl -pi -e 's/KEYWORD1/KEYWORD2/' foo
# or:
perl -pe 's/KEYWORD1/KEYWORD2/' < foo
# or:
another_command | perl -pe 's/KEYWORD1/KEYWORD2/'

PSEXEC write in new instance [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 3 years ago.
Improve this question
I am a beginer in dev in new enterprise.
I use Psexec to open a new instance of CMD (with sdial)
I try to write inside but this is not working, look picture and code for to be clear
psexec.exe -d -i -s cmd /c "echo toto & sdial &echo toto"
I want write "toto" like this picture (i have typed with keyboard but i want write "toto" with bat or powershell)
in taskmanager I have sDIal.exe in command line (maybe can help you)
How to write inside cmd window call "sDial" with bat or powershell ?
last edit
#mklement0 rep to my ask sucessfully
Now i try to register in txt but this is not working
psexec.exe -d -i -s cmd /c "echo toto | sdial" >> output.txt
there is not txt file ...
It sounds like you're trying to provide input to an interactive prompt that program sdial presents.
You can try to pipe (|) this input to sdial:
psexec.exe -d -i -s cmd /c "echo toto|sdial"

sed: Why does a file being edited in-place have modified lines doubled? [duplicate]

This question already has answers here:
sed is printing a substituted line twice
(2 answers)
Closed 6 years ago.
The perils of working tired:
sed -i 's/foo/barbazqux/p' example.txt
This made the output file have two copies of any modified line.
Turns out I hadn't removed the p flag from the end of the command. I'd been doing this when testing it on the command line.
Correct command:
sed -i 's/foo/barbazqux/' example.txt

Grep sed command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anybody say me what does this command mean? Thanks
grep -h -o "\#string\/\(\w*\)" * -R | sed "s!#string\/\(\w*\)!\1!p" | sort | uniq > ..\AndroidProject1\tmp_used_strings.txt
This command will give you the list of string which is used in android layout xml file.
grep -h -o "\#string\/\(\w*\)" * -R
-R - Recursive searching
-h - no file name
-o - print only matched part of string
This command will give you the exact match string. Then, you are piping this output to input of sed command.
sed "s!#string\/\(\w*\)!\1!p"
This command will parse the input and separate the name. Then, sorting the result and store the uniq values to the file.
For more information about options, see the man page of command.

How do I compare two source trees in Linux? [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 have two directories containing source files to a project I've inherited with little by way of documentation. How do I compare both directories to make see what the differences are?
Try this:
diff -Naur dir1/ dir2/
The -u option makes the output a
little easier to read.
The -r option recurses through all
subdirectories
The -N and -a options are really
only necessary if you wanted to create
a patch file.
You can try Meld. It is a wonderful visual diff tool ;-)
diff -u -r dirA dirB
Will show you a unified recursive diff between the files in dirA and dirB
You may use the diff command in the shell. Or install a tool like KDiff3.
The diff command to compare directories kept telling me that I didn't have differences, when I knew there were differences.
Instead of using diff directly, I used a sorted list of md5sums and then compared those files with diff:
find /path1/dir/ -type f -exec md5sum {} + | awk '{print $2 $1}' | sort >! path1.log
find /path2/dir/ -type f -exec md5sum {} + | awk '{print $2 $1}' | sort >! path2.log
gvimdiff path1.log path2.log
If the beginning part of the path is causing headaches, then change it. Select the Path1 window and type:
:%s|path1|path2|g
This will replace all instances of path1 with path2 in the first file, and now your diff should only show differences.