bash awk codes to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash awk codes to perl
# 1  
Old 03-15-2008
bash awk codes to perl

Hi,

I am interesting in writing the following bash codes into perl

My script is simple take field 2 in /etc/passwd and put into an array

#!/bin/bash
PASSWD_FILE=/etc/passwd
A=(`awk -F: ' { print $2 }' $PASSWD_FILE `)

Can someone give me equivalent codes in perl ?
# 2  
Old 03-15-2008
how about trying it out

1) read the file line by line using while loop
2) split the line by ":" as delimiter
3) get the second element using array indices.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk color codes based on condition

HI i have two files say test and test1 Test.txt Code: Lun01 2TB 1.99TB 99.6% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Lun04 2TB 1.55TB 89.6% Code: Test1.txt Lun01 2TB 1.99TB 89.5% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Requirement is to compare... (6 Replies)
Discussion started by: venkitesh
6 Replies

2. Shell Programming and Scripting

BASH - Propagation of error codes

Hello. I use bash functions which are in different script files. Theses scripts function files are sourced when necessary. As function does not easily return string value, Value are return using the echo function, and a return code is returned.. Now here my question : In the main script I... (11 Replies)
Discussion started by: jcdole
11 Replies

3. Shell Programming and Scripting

Search strings and highlight them using Perl or bash/awk/sed

Hi, I have two files: a.doc and b.txt I wish to search the strings from file b.txt in a.doc and want to highlight them in a.doc with different colours using Perl or bash./awk/sed? Please guide me. :) Thanks!!!!! (10 Replies)
Discussion started by: bioinfo
10 Replies

4. Shell Programming and Scripting

Rsync script to rewrite suffix - BASH, awk, sed, perl?

trying to write up a script to put the suffix back. heres what I have but can't get it to do anything :( would like it to be name.date.suffix rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~" --bwlimit=1024 /mymounts/test1/ /mymounts/test2/ while IFS=. read -r -u 9 -d '' name... (1 Reply)
Discussion started by: jmituzas
1 Replies

5. Shell Programming and Scripting

Bash Shell Script Exit Codes

Here is my daily stupid question: How can I tell a script to only execute if the other scripts exits successfully? So "script A" executes and it executes successfully (0),then "script B" will run or else "script A "executes and it exits unsucessfully (1) then "script B" will read return... (6 Replies)
Discussion started by: metallica1973
6 Replies

6. Shell Programming and Scripting

'watch' not interpreting escape codes in bash script

Hi there, I'm fairly new to bash scripting and already having some troubles. I'm making a script that can print some series of strings in colors based in the information of a file, for simplicity let's say it only does: #!/bin/bash printf "\eWhen you execute this in the command line it... (1 Reply)
Discussion started by: Arashi
1 Replies

7. Shell Programming and Scripting

Perl - How do you break the long line of codes into 2?

I'm trying to make this long line of codes in Perl looks nice by dividing it into 2 lines... Before: `echo "blahblahblahblahblahblahblahblahblahblahblah" > ~/lalala/lalala/lalala/lalala/lalala/abc`; After: `echo "blahblahblahblahblahblahblahblahblahblahblah" > ... (5 Replies)
Discussion started by: teiji
5 Replies

8. UNIX for Dummies Questions & Answers

combine two awk codes

Hello How do I combine the following 2 codes in one, the purpose is to not generate the outfile1 awk '{print $9 "\t" $10 "\t" $11}' infile > outfile1 awk '{ gsub(/.fa/,""); print }' outfile1 > outfile2 Thanks Joseph (2 Replies)
Discussion started by: jdhahbi
2 Replies

9. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

10. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies
Login or Register to Ask a Question