VI for UNIX Question ...

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers VI for UNIX Question ...
# 1  
Old 06-22-2011
VI for UNIX Question ...

Hi All,

I have a sync report file in the following format:

root@####: updating host ####
root@####: /opt/dba/bin/ need to update
root@####: /opt/sysadm/bin/ need to update
root@####: /opt/sysadm/bin/ need to install
root@####: /opt/sysadm/lib/####.dist.20110131: need to install
root@####: updating host ####
root@####: /opt/dba/bin/ need to update
root@####: /opt/sysadm/bin/ need to update
root@####: /opt/sysadm/bin/ need to install

I want to use the UNIX cut command to get rid of the first column (root@####: ) stuff. Trying to trim the file down so I can get to the file lists by using delimiters like fields and colons.

I want to use something like the following:

!cut -d: -f2

I just need easier ways to trim these documents and get to the file lists. I know there are ways using regular expressions, but I've used the

format before. Now it doesn't work for some reason.

Any input would be appreciated.


Last edited by pludi; 06-24-2011 at 12:40 PM..
# 2  
Old 06-22-2011
sed 's/root@####://g' file > outfile

This User Gave Thanks to Peasant For This Post:
# 3  
Old 06-22-2011
Thanks but the #### part of the server address is different. So I have multiple lines containing different addresses in the same format. Which is why I want to work with columns as opposed to lines.
# 4  
Old 06-22-2011
I don't see why cut with the appropriate delimiter doesn't work, unless there are colons in the characters you've masked out. Perhaps you can try an awk equivalent:
awk -F: '{print $2}' file

This User Gave Thanks to alister For This Post:
# 5  
Old 06-22-2011
Well, it's not that the cut command doesn't work. It does what I don't want it to do. Or, I should say, that I should trim the file first.

Your suggestion alister works in the same way my original cut command worked. It does however get rid of stuff I need to stay in the file.

Sorry, I should add that there is also more lines of the pattern that has more fields, i.e.:

root@#####: #####: /opt/dba/results/res03301.r: need to remove
As you can see these lines contain one additional column, so they are different than the rest of the lines in the file. most contain three columns delimited by a colon. This one has an additional column delimited by a colon, and that is why the cut and awk command display what I don't want them to.

I would like to get rid of the first column, initially. Then get rid of the lines containing different number of columns.

So this is kind of what I need to get to be able to do:

  • I need to get rid of the first column.
  • I would like to delete a pattern (the second set of #### on the lines that are 4 fields instead of three delimited by colons) from every line that contains it.
  • I would actually like to keep the patterns "need to update", "need to remove" located on the 3-rd column initially for identification purposes before deleting them.
# 6  
Old 06-22-2011
This a good start?

mute@geek:~/test$ awk 'BEGIN { FS=":" } NF > 2 { print $(NF-1) $NF }' sync
 /opt/dba/bin/ need to update
 /opt/sysadm/bin/ need to update
 /opt/sysadm/bin/ need to install
 /opt/sysadm/lib/####.dist.20110131 need to install
 /opt/dba/bin/ need to update
 /opt/sysadm/bin/ need to update
 /opt/sysadm/bin/ need to install
 /opt/dba/results/res03301.r need to remove


I think the problem with your 'cut' was that you really wanted
cut -d: -f2-

to keep the 'needs updating', or in case of the removing line with extra column.

Last edited by neutronscott; 06-22-2011 at 04:39 PM..
This User Gave Thanks to neutronscott For This Post:
# 7  
Old 06-22-2011
Thanks neutronscott,

That "cut" bit was an eye-opener. Still the issue of having that additional column (####: ) stay in there.

Is there a way to selectively erase a pattern (i.e. ####: ) from a line, on every line in the file?

Last edited by zixzix01; 06-22-2011 at 04:52 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question on UNIX

Hi, Can you please advise on answers of below 4 questions as I am not sure on the answers. 1. You are porting a C program that interacts over a network with remote systems. The program was originally written on AMD64 Linux. You are migrating it to SPARC Solaris architecture. Question Based on... (1 Reply)
Discussion started by: Vivekit82
1 Replies

2. UNIX for Dummies Questions & Answers

UNIX question

Pleas I want answer this question or reference or link website can find answer to this question? 1. We consider that we are running on a UNIX system which uses ACL as a mechanism for file protection. Where is the protection information of the file stored? 2. In UNIX, each device is... (1 Reply)
Discussion started by: tamer11007
1 Replies

3. UNIX for Dummies Questions & Answers

Unix question

When you enter your login id and password, what determines what program startsup? Is it always a Unix shell? (3 Replies)
Discussion started by: Alice Klein
3 Replies

4. Solaris

Unix Question

IF A program or database routine is writing in a file laying on unix box then how can be identify the process id which is writing in the file. Please let me know how can we do using root command and without root command? Regards, Shashank (10 Replies)
Discussion started by: TAPARIA
10 Replies

5. UNIX for Dummies Questions & Answers

Question about unix

Hey everyone i am new to unix as well, has anybody heard of the script that allows you screen to look just like the Windows screen, if yea, what is it? (3 Replies)
Discussion started by: Gueso
3 Replies

6. UNIX for Dummies Questions & Answers

Unix History Question: Why are filenames/dirnames case sentsitive in Unix?

I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Discussion started by: deckard
3 Replies

7. UNIX for Dummies Questions & Answers

Unix 10.2 question

I'm a verteran to Windows but i newbie to UNIX so i hope this isn't too dumb of a question. I have an HP 9000 D Class Server that has 10.2 and uses a console. The console died and i was told i can put a standard EISA video card in it and use a regualr monitor and keyboard. My question is how do i... (5 Replies)
Discussion started by: egress1
5 Replies

8. IP Networking

unix to unix serial connection question

hi there i'm a new bie just got few simple questions to ask. I got expert in windows configuration but totally new to unix environment . I want to make sure a com port (com1) is working, so I connect a 9-pin cable (CB9) for both PC using Unix environment (unix to unix). The question are (1)... (1 Reply)
Discussion started by: typsam
1 Replies

9. UNIX for Dummies Questions & Answers

unix question

How might you look at the last mail message someone sent you , without running the mail utility? (1 Reply)
Discussion started by: swetha
1 Replies
Login or Register to Ask a Question

Featured Tech Videos