Line editing


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Line editing
# 1  
Old 07-02-2008
Line editing

I have some trouble editing a line. My aim is to edit the first line of a file.It will look the code and if there are dummy characters at the begininng of line before < it will erase. It is a php code.For instance:
for instance if the first line is like
%^<?php>sadsa</php>, it will change it to
<?php>sadsa</php>
thanks in advance
Of course it is a bash scriptSmilie

Last edited by king87; 07-02-2008 at 04:40 AM..
# 2  
Old 07-02-2008
Code:
echo '%^<?php>sadsa</php>'| sed 's/^[^ <]*//1'
<?php>sadsa</php>

# 3  
Old 07-02-2008
using Perl:
Code:
perl -pi -e 'if (/^(.*?)\</) { s/^(.*?)\</</ }' filename

# 4  
Old 07-02-2008
but the beginning of line can be changeable it can start abc or cde, what it will do, delete what ever in front of the first < and make the line start with <
besides it will change the original file
# 5  
Old 07-02-2008
Thanks, but now I am trying that in each line
everything except < and > with it inside of them for example sadas<sadasdass>.,s
it will change every line like that to <sadasdass>
Thanks in advance
# 6  
Old 03-04-2009
echo "abc<sadsa>fds" | sed 's/.*\(<.*>\).*/\1/'
<sadsa>
# 7  
Old 03-04-2009
echo "pre<?php>abc</php>last" | sed 's|.*<?php>\(.*\)</php>.*|\1|'
abc
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing in vi - adding words to a line

i have lines in a file similar to this: results=$(echo Total: ${res} | command | command) now I need to add text before the word "results", but i dont know how to do it. here's what i tried: %s~results=.*echo Total:.* ${7}~PROCESS \; results=.*echo Total:.* ${7}~g the problem is,... (1 Reply)
Discussion started by: SkySmart
1 Replies

2. Shell Programming and Scripting

Editing the next line of the pattern

Hi All, I am trying to edit the next line when there is a success for a pattern. For example: <nvname>abc</nvname> <nvvalue>1</nvvalue> <nvname>def</nvname> <nvvalue>2</nvvalue> once there is a hit for the string "abc" the value of the nvvalue should be replaced with the value we... (5 Replies)
Discussion started by: pulgupta
5 Replies

3. Shell Programming and Scripting

Editing the first line of file

I have a sample file as below :- RECORD_COUNT|2660|28606946.86|20110701122349694| adkad|wwsgesg|mkmk|FFFF|FAFAF|FFAF|FAFFFFA|5894858| I have to replace the second coulmn in the first row which is the count of no of lines in the file from a new variable . Also I have to delete the 3rd... (2 Replies)
Discussion started by: Sanjeev Yadav
2 Replies

4. UNIX for Dummies Questions & Answers

Help with editing 2nd line after match

Hi All I would like to break down each next line that matches SK1.chr* in this case NNNNNN.... into 100 characters each after SK1.chr*... (3 Replies)
Discussion started by: pawannoel
3 Replies

5. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

6. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

7. Shell Programming and Scripting

awk line editing

Hello I am trying to make an awk script that always replaces the same characters in a file, with white space in between. Can anyone write a script that prompts for the 3 numbers and then replaces them in the file? eg. enter a b c: 'it then puts a b c in the file. The file format is always ... (12 Replies)
Discussion started by: gav2251
12 Replies

8. Shell Programming and Scripting

Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place?... (1 Reply)
Discussion started by: gator76
1 Replies

9. Shell Programming and Scripting

Editing last line of a file

Hi All, Could you please help me out with this problem? I need to edit the last line of my file. Ex: The last line in my file will be say 000056000045 8 I need to subtract some number from the number 45 and replace the new number in its place. ... (1 Reply)
Discussion started by: Anitha Chandran
1 Replies

10. UNIX for Dummies Questions & Answers

editing bash command line with vi

Is there a way using bash that I can edit a command line using vi. I.e. if I have a long command line and I want to edit it.....by typing vi and then having the command open in an editing window.... I beleive this can be done in k shell by pressing v....however can find out how this can be... (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question