LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2017, 02:55 AM   #1
Asoo
LQ Newbie
 
Registered: Apr 2017
Posts: 29

Rep: Reputation: Disabled
Replace numbers with another numbers using sed in multiple files


Hi,

I have made 50 copies of a file. I want to change the "10" to "11","12"...."50" in the contents of file. File format is 10.txt, 11.txt .... 50.txt. So 11.txt, should replace the 10 with 11 in the file, 12.txt replace 10 with 12.. 50.txt replace 10 with 50.

I am trying to use sed. The command I have written just as a test to replace the number 10 with another number:

Code:
counter=11 ; for i in *.txt ; do sed -i "s/10/$counter/g" $i ; counter=$((counter+1)) ; done
It is replacing the whole line with blank, where it finds "10".

Thanks.

Last edited by Asoo; 05-31-2017 at 03:51 AM.
 
Old 05-31-2017, 03:36 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,639

Rep: Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615
It looks like it is working for me.
you can insert set -xv at the beginning to see what's happening.
 
2 members found this post helpful.
Old 05-31-2017, 03:57 AM   #3
Asoo
LQ Newbie
 
Registered: Apr 2017
Posts: 29

Original Poster
Rep: Reputation: Disabled
I inserted set -xv and had a look at it. It started working, it was a small problem. I used the same line and it worked perfectly. Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search multiple files having certain numbers Haba2015 Linux - Newbie 9 11-04-2015 04:09 PM
[SOLVED] Print numbers and associated text belonging to an interval of numbers Trd300 Linux - Newbie 27 03-11-2012 05:58 AM
[SOLVED] find the total of numbers that are higher than x in a text file with numbers (using awk??) Mike_V Programming 12 11-24-2010 09:51 AM
[SOLVED] Replace sequential numbers in a file with a different sequence using sed thefiend Linux - Newbie 6 04-12-2010 10:29 PM
how to replace numbers in vi ? gandi71 Linux - Software 4 04-03-2006 04:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration