printing patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing patterns
# 1  
Old 12-28-2011
printing patterns

I have the following file :

1 2 3 4 5
6 7 8 9 0
9 8 7 6 5
4 3 2 1 0

0 1 2 3 4

Write scripts to
get the following outputs :

A)

1
7
7
1
4

B)

1 2 3 4 5
6 7 8 9
9 8 7
4 3
0

please give a solution...
# 2  
Old 12-28-2011
Sounds like homework... any trials?...

a clue!...
Code:
root@bt:/tmp# awk '...' infile
1 2 3 4 5
6 7 8 9
9 8 7
4 3
0
root@bt:/tmp# awk '...' infile
1
7
7
1
4

--ahamed
# 3  
Old 12-28-2011
please try using arrays or search and cut options

---------- Post updated at 12:18 AM ---------- Previous update was at 12:17 AM ----------

use awk
# 4  
Old 12-28-2011
# 5  
Old 12-28-2011
solutions

this ids my idea i got the result
ans B)
#!/bin/bash
cat p | sed -n 1p |cut -d " " -f1-5
cat p | sed -n 2p |cut -d " " -f1-4
cat p | sed -n 3p |cut -d " " -f1-3
cat p | sed -n 4p |cut -d " " -f1-2
cat p | sed -n 6p |cut -d " " -f1
ans A)
#!/bin/bash

for (( i=1; i<=4; i++ ))
do
cat p | sed -n $i\p | cut -d " " -f $i
done
cat p | sed -n 6p | cut -d " " -f 5

can anyone do the ist one using "for" loop.... give solution
# 6  
Old 12-28-2011
Code:
i=1;while read x;do echo $x | cut -d" " -f"$i";i=$(($i + 1));done < p

---------- Post updated at 14:27 ---------- Previous update was at 14:23 ----------

Code:
awk 'BEGIN{i=0}++i{print $i}' p

If this is homework, your prof is never gonna believe you wrote these one-liners.
# 7  
Old 12-28-2011
one more .. Just a try .. Smilie
Code:
$ nawk '{print "echo \""$0"\"|cut -d\" \" -f"NR } ' infile | sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Printing a block of lines from a file, if that block does not contain two patterns using sed

I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed. See below for the example data. ................................server 1............................... running process 1 running... (8 Replies)
Discussion started by: Kesavan
8 Replies

5. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

6. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

7. UNIX for Dummies Questions & Answers

Printing the lines using search patterns

Hi all , i need an help here.!!!! i have a file that contains /etc/passwd files from some servers. i need a script which search for presence of a user in the servers. like if i give 51144 to the script. the should be o/p Please help on this..... (4 Replies)
Discussion started by: sudharson
4 Replies

8. UNIX for Dummies Questions & Answers

printing only the middle word between two patterns

How would I print the word "and" between the words "FOO" and BAR" using sed? My file has three words in it FOO and BAR. I only want the word "and". Thanks every one. (7 Replies)
Discussion started by: tigta09
7 Replies

9. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

10. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies
Login or Register to Ask a Question