Insert comments in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert comments in a loop
# 1  
Old 07-08-2014
Insert comments in a loop

I got an output file where I have insert some comments inbetween
e.g.

My file looks like this---
Code:
userA   10.120.xxx.xxx   Jan 21   01:00   03:00   userA1
userB   10.120.xxx.xxx   Jul 03    10:00   13:00   userB1
userC   10.120.xxx.xxx   Aug 04  14:00   21:00   userC1

I Would like to write a new file which looks like this...
Code:
"Employee" userA1 "logged into" 'hostname' "at" 01:00 "on" Jan 21 "as OS user" userA "and logged off at" 03:00

Thanks


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 07-08-2014 at 05:23 AM..
# 2  
Old 07-08-2014
Code:
perl -ne '@r=split/\s+/,$_;printf "Employee %s logged into %s at %s on %s as OS user %s and logged off at %s", $r[6],$r[1],$r[4],"$r[2] $r[3]", $r[0], $r[5]' <filename>

# 3  
Old 07-08-2014
I would like to have a shell command for this please...

Thanks
# 4  
Old 07-08-2014
Here is a shell script:

Code:
host=`hostname`
while read usrid ip mon day in out name ignore
do
    echo "Employee $name logged into $host at $in on $mon $day as OS user $usrid and logged off at $out"
done < infile

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 07-08-2014
Thanks !! It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete Comments

Hello i am back :D, i have a prolem. I want to Delete the IPs which are in Comments. Input 192.168.0.1 192.168.0.2 #192.168.0.3 #192.168.0.4 - when TAB or Space, delete too. /*192.168.0.5 192.168.0.6 192.168.0.7*\ Output 192.168.0.1 192.168.0.2 My solution is sed -e... (7 Replies)
Discussion started by: eightball
7 Replies

2. Shell Programming and Scripting

insert predefine text in front and on a loop

Hi Experts, I wish to insert predefined text in front of every line and this needs to be in a loop because it is always expanding. Before : 11111111 22222222 33333333 44444444 55555555 77777777 88888888 00000000 To be Inserted : a= b= (2 Replies)
Discussion started by: masayangbata
2 Replies

3. Shell Programming and Scripting

print only comments

I want to write a shell script which it takes as argument a java file or a c++ file (.java or .cpp). It will check if the file is type of java or c++, else it ends with error message. If all are ok, it will call awk that prints only the comments that the java or c++ file contains, grouping and... (5 Replies)
Discussion started by: Mark_orig
5 Replies

4. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

I must write a script to change all C++ like comments: // this is a comment to this one /* this is a comment */ How to do it by sed? With file: #include <cstdio> using namespace std; //one // two int main() { printf("Example"); // three }//four the result should be: (2 Replies)
Discussion started by: black_hawk
2 Replies

5. Shell Programming and Scripting

delete comments

Delete everything comes in between /* & */. Current File: ==================== create or replace procedure test421 is begin /* ---sasasas/*dsdsds */ dbms_output.put_line('SAURABH'); END; To be File: =================== create or replace procedure test421 is begin... (10 Replies)
Discussion started by: susau_79
10 Replies

6. Shell Programming and Scripting

Scripting comments

Anyone have a good link for documentation conventions for scripts? (4 Replies)
Discussion started by: gliesian
4 Replies

7. Programming

lint comments

Hi can anyone help me regarding the meaning of the following lint messages. what is the use of having such lint comments in the c program. /*lint -esym(534,cputs,fgets,cprintf) */ /*lint -efile(766,pragmas.h) */ Thanks a lot in advance. (5 Replies)
Discussion started by: axes
5 Replies

8. UNIX for Dummies Questions & Answers

Remove comments...

It may be a no-brainer, but the answer is escaping me right now: I'm trying to write a little script to remove all comments from .c source... I was thinking sed, but I'm not a very strong regexp user (e.g. I suck with sed). I tried dumping the file into: sed -e 's/\/\* * \*\///g' and several... (1 Reply)
Discussion started by: LivinFree
1 Replies
Login or Register to Ask a Question