search change write


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers search change write
# 1  
Old 03-18-2008
search change write

Code:
i="1"
while [ $i -le 1000 ]
do
    k=`expr $i + 1`
    sed -e 's/"$i"/"$k"/' < somefile1.txt >> somefile2.txt
    i=`expr $i + 1`
done

ive been trying to :
1 from a file containing numbers in a row divided with correct number of spaces to find the corresponding one
2 change the value
3 and append it to somefile2.txt

problems
the somefile2.txt remains empty

HELP pls

Last edited by Yogesh Sawant; 03-18-2008 at 09:12 AM.. Reason: added code tags
# 2  
Old 03-18-2008
Hi,
Try the below script,
Code:
i="1"
while [ $i -le 1000 ]
do
    k=`expr $i + 1`
    cat somefile1.txt | sed -e 's/"$i"/"$k"/'  >> somefile2.txt
    i=`expr $i + 1`
done


Last edited by Yogesh Sawant; 03-18-2008 at 09:14 AM.. Reason: added code tags
# 3  
Old 03-18-2008
doesnt work
somefile2 created but empty
the somefile1 format is
Code:
00000214   5    1         12   49     38   49                  01-01-2008 14:05:14       10  59       45 32 CMS.32.STUT.I.20080105_153445_P_0296.dat  20          0718174439

thanks, never the less

Last edited by Yogesh Sawant; 03-18-2008 at 09:15 AM.. Reason: added code tags
# 4  
Old 03-19-2008
The reason is simple: inside single quotes the double quotes lose their function and revert back to being simple characters. Try it yourself:

Code:
# x="xxx"
# print $x
xxx
# print "$x"
xxx
# print '"$x"'
"$x"

The same you have done in your sed-script.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change the write in file

Hello I have a file log with one information in many lines but i want the information log just per line. How can i do to do this in shell langage. Input file : Info : etstst trerer tetststsss Warning : informatopnn eysysysysys rererererer Error : this is an... (9 Replies)
Discussion started by: boudake
9 Replies

2. Shell Programming and Scripting

Search text beween tags and write to file using awk

Hi Friends, I have a very big text file, that has code for multiple functions. I have scan through the file and write each function in seperate file. All functions starts with BEGIN DSFNC Identifier "ABCDDataValidationfnc" and ends with END DSFNC I need create a file(using identifier)... (2 Replies)
Discussion started by: anandapani
2 Replies

3. Shell Programming and Scripting

Search pattern and write line into another file

Hi, I have a file which contains the below details.. My requirement is to fetch all the lines which are starting with "ABC_XY_" into 1 file and rest of the lines (not starting with "ABC_XY_") into another file. Could you please help with what command needs to be used? file1.txt ----------... (12 Replies)
Discussion started by: satyaatcgi
12 Replies

4. Shell Programming and Scripting

search any user files with write permission

Guys, i wanna get any user files with write permission (on user or group permission) for review but i confuse with -perm parameter. any body can help me to explain what is that mean? thank's (1 Reply)
Discussion started by: michlix
1 Replies

5. Hardware

Hardware Correction: How to change DVD write speed

I am now on Kernel 2.6.32-26 For me 16x CD write speed is okay. I have old hardware which was able to write DVDs at 1x, back in previous linux version. Now, I dont get speed of less than 4x. Tested on k3b, xfburn, and brasero. But all start at bottom 4x write speed. k3b forced back to... (0 Replies)
Discussion started by: makh
0 Replies

6. Shell Programming and Scripting

Help required to write shell script to change passwd

Hi All, I wanted to write a shell script which will change the expired passwd in oracle. Here is below what I am trying, #!/bin/sh set -x ORACLE_HOME="/optware/oracle/9.2.0.2_64" SQLPLUS="${ORACLE_HOME}/bin/sqlplus" PASS="xyz" PATH=$ORACLE_HOME/bin:$PATH... (0 Replies)
Discussion started by: gr8_usk
0 Replies

7. Shell Programming and Scripting

how to write script to change email address

we have 4000 html pages that need an email address changed. eg) company@yahoo.com to company@hotmail.com we only want the file modified date to be changed when there has been a change to the file. Should I be using grep? I fairly new to UNIX and was told to using something like... (2 Replies)
Discussion started by: mchelle_99
2 Replies

8. Shell Programming and Scripting

write shell script to search file in folder

hi .. i have a problem how to search file with date and version number(ms_2.0_dd/mm/yy_24)in folder.Here 24 is version number and compare the this file to other file which is in another folder and if does not match then copy this file to respective folder.Also copy different files in different... (1 Reply)
Discussion started by: shubhig15
1 Replies

9. Programming

How to write a code in C to search a file

Dear All, Plz give me some code that how can I search a file through a C program file may be in Present Directory or in its Sub-Directories and it should support Linux Platform. :mad: (6 Replies)
Discussion started by: krishna_sicsr
6 Replies

10. UNIX for Dummies Questions & Answers

search change write

i="1" while do k=`expr $i + 1` sed -e 's/"$i"/"$k"/' < somefile1.txt >> somefile2.txt i=`expr $i + 1` done ive been trying to : 1 from a file containing numbers in a row divided with correct number of 2 spaces to find the corresponding one 2 change the value 3 and append... (1 Reply)
Discussion started by: trilicno
1 Replies
Login or Register to Ask a Question