change in file requires


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change in file requires
# 1  
Old 09-18-2008
change in file requires

Hi,

i have one file, filename -> a.txt, i want that simple way just enter command and it will do that, not through redirection way.


AAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFF

i want to disable line2 like

#BBBBBBBBBBBBBBBBBBBBBBB

and wants to add another line after line4 [ZZZZZZZZZZZZZZZZZZ] so output shows like that.



AAAAAAAAAAAAAAAAAAAAAAA
#BBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDD
ZZZZZZZZZZZZZZZZZZZZZZZ
EEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFF

Thanks,
Bash
# 2  
Old 09-18-2008
Code:
awk -v newline="ZZZZZZZZZZZZZZZZZZ" '
NR == 2 { printf "#" } 1
NR == 4 { print newline }' FILENAME

# 3  
Old 09-18-2008
its not doing anything.

Thanks,
bash
# 4  
Old 09-18-2008
try this....
Quote:
awk '{if(NR==2)print "#"$0; else if(NR==4)print "ZZZZZZZZZZZZZZZZZZZZZZZ\n"$0; else print $0}' filename
# 5  
Old 09-18-2008
this is displaying only, i want i just press enter it will do both change, as my main motive is no redirection method.

Thanks,
bash
# 6  
Old 09-18-2008
Quote:
Originally Posted by learnbash
its not doing anything.

Sure it is. What do you want it to do?

If you want it to change the file, redirect the output to a new file then copy or move it over the original file.
# 7  
Old 09-18-2008
yes, i sure.

my question is
__________________________

Hi,

i have one file, filename -> a.txt, i want that simple way just enter command and it will do that, not through redirection way.


AAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFF

i want to disable line2 like

#BBBBBBBBBBBBBBBBBBBBBBB

and wants to add another line after line4 [ZZZZZZZZZZZZZZZZZZ] so output shows like that.



AAAAAAAAAAAAAAAAAAAAAAA
#BBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDD
ZZZZZZZZZZZZZZZZZZZZZZZ
EEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFF
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Requires a script for incidents

Hi, I am associated with a project where we received multiple incident on daily basis for different support groups like(unix support,windows support,vms support). We use HP service centre as a ticketing tool where we gets all the incidents generated automatically when something went wrong on... (2 Replies)
Discussion started by: naman agarwal
2 Replies

2. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

3. Solaris

Solaris 10 requires Update 4 (08/07)

Can anybody help me how can we upgrade to Solaris 10 requires Update 4 (08/07) from Solaris 10 6/06. cat /etc/release Solaris 10 6/06 s10s_u2wos_09a SPARC Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. Use is subject to... (4 Replies)
Discussion started by: Asteroid
4 Replies

4. Shell Programming and Scripting

change requires with perl

Hi, i need to change a file with perl having contents below, but it will not do any action if change is being already made. file.txt AAAAAA BBBBBB CCCCCC output.txt (that required) AAAAAA #BBBBB DDDDDD CCCCCC Thanks, (2 Replies)
Discussion started by: learnbash
2 Replies

5. Shell Programming and Scripting

Script calls command that requires input

Greetings, Newbie here on the site. I have searched for a similar issue but am not finding one. I have a script that invokes a command if text is found in a file. The command asks for a y/n response, but is not an option on the command, i.e. `command -y`. I am familiar with the <<EOF, but I... (5 Replies)
Discussion started by: 22blaze
5 Replies

6. SuSE

freedce requires libdcethreads!

hello every one, here i am attempting to install freedce-1.1.0.7 on HP-UX machine. in that process i ran a command ./configure at command prompt. it's throughing the following error; configure: error: freedce requires libdcethreads! here i am pasting the ./configure output with... (1 Reply)
Discussion started by: mannam srinivas
1 Replies

7. UNIX for Advanced & Expert Users

Configured sftp still requires password

Hi Gurus:) I have to connect from a SunOS 5.10 to a 5.8 using sftp in BatchMode. For this, I have generated a Public-Key (ssh-keygen -b 1024 -P "" -t dsa) on the 5.10 and saved it in ~remote-user/.ssh/authorized-keys on the 5.8. Then, running either one of ssh or sftp, it asks for the... (24 Replies)
Discussion started by: unilover
24 Replies

8. Shell Programming and Scripting

SFTP error:-b requires an argument greater than zero

Hi when i execute the below command sftp -b ftpCommand.ksh remoteuser@remoterserver i am getting the error "-b requires an argument greater than zero" Please can any one help me. (4 Replies)
Discussion started by: vgs
4 Replies

9. UNIX for Advanced & Expert Users

SFTP error:-b requires an argument greater than zero

Hi when i execute the below command sftp -b ftpCommand.ksh remoteuser@remoterserver i am getting the error "-b requires an argument greater than zero" Please can any one help me. (1 Reply)
Discussion started by: vgs
1 Replies

10. Shell Programming and Scripting

New User Requires Help

Hi, I am a new Unix user and I would like to know which link to go to in order to learn Unix online. Something like tutorials for beginners (1 Reply)
Discussion started by: John K. Mbuki
1 Replies
Login or Register to Ask a Question