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 11-22-2015, 07:41 AM   #1
Bobbic
LQ Newbie
 
Registered: Nov 2015
Posts: 4

Rep: Reputation: Disabled
wrong submission in a for loop by usind the sed order


Hey Guys,

I have a problem with my code. I have a lot of .dat files. In these files I want to change one expression to another.

My code is this:

let a=34;

for i in V13_*.dat;

do let a=a+1;
sed -i 's/Slice: Z=0.00635/V13_'$a'/' V13_*.dat;
echo $i;
echo $a;
done

My Problem is that every expression is changed to V13_35 and not to

V13_35
V13_36
V13_37
...

I think I have to submit the a into the sed-function, because echo $a shows

35
36
37
...

Someone get it?

Can you help me?

Tanks a lot.
 
Old 11-22-2015, 07:56 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Your sed is operating on all files at the same time V13_*.dat, it should be operating on "$i"
 
Old 11-22-2015, 08:32 AM   #3
Bobbic
LQ Newbie
 
Registered: Nov 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Wow. Great. It works. Thank you =)
 
Old 11-22-2015, 12:00 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Good

Please do 2 things though:

1. In future please use [code][/code] tags around code and data to keep its formatting

2. Once you have a solution, please mark question as SOLVED
 
  


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
Reverse the order of lines using sed Karljoe2 Programming 4 12-26-2012 10:38 AM
2 soundcards, wrong order (debian) hate29 Linux - Hardware 12 12-03-2006 03:18 PM
Partitions in wrong order?? king_scott_2 Linux - Hardware 4 12-11-2005 04:37 PM
Partitions in wrong order nukey Slackware 5 05-15-2005 05:50 AM
Wrong soundcards order Bothkill Slackware 11 07-22-2004 05:10 PM

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

All times are GMT -5. The time now is 09:17 PM.

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