LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2011, 01:44 PM   #1
geehog
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: 0
Multiple input into seq command from pipe / single column unique numbers


Have this script which is reading in a series of files, one at a time with while-do-done loop, each file goes through various greps/awk's where this info is then saved to various files for later use. i.e....

Script is being run on Linux Red Hat,
#! /bin/bash

...etc ..
etc..

while (( somme > 0 )); do


declare -i sme=$(( $dmlmax - $dml ))

fne="01_????-""0$dml"".txt"

if test -f $fne; then

grep "Elap Time =" $fne | awk '{print $3}' > elp.txt
grep "on Nole" $file_name | awk '{print $3, $9)}' > nole.txt
....etc..
....etc...
grep ....

...
done

In one of the grep/awk's the output (currently) are 2 columns (min max), i.e....| awk '{print $1, $2}' | sort -u which outputs (e.g.)

1 3
2 2
33 35
40 40
and on ...
..and on...
...


The number of "min max" pairs varies from file to file. Want to output a single column of unique numbers from the min max pairs & get the number of them for input to a file...i.e...

.....| sort -u | <PROCESS> | sort -u | wc | awk '{print $1}' > z.txt

where <PROCESS> is some process/technique that will generate a single column of integers (increment of 1) to pipe into the next one (sort -u)

i.e. (example from above)
1
2
3
2
33
34
35
40

Have tried command seq - only works for single pair input i.e.
.|awk '{print $1, $2}' | sort -u | tail -1 | seq `awk '{print $1, $2}'`

Is there any command like seq etc which will output a single column based on a input of min max numbers (increment 1) to pipe onwards to next command?
 
Old 05-13-2011, 03:58 PM   #2
Couling
Member
 
Registered: Oct 2007
Posts: 30

Rep: Reputation: 15
I'm a little unshore what you're asking for.

It sounds like you want to flatten out two columns into 1:

a b
c d

into

a
b
c
d


If so then may I suggest that awk is your friend here.
It's a full on programming language in a single command.
Code:
awk '{print $1; print $2}'
Its worth looking up some tutorials on awk is so often used for one stage in a pipe when it will do the task of the whole pipe.
If you can't find anything shorter then: http://www.gnu.org/software/gawk/manual/gawk.html#Regex

For example you often see this in scripts:
grep foo | awk '{print $1}'

Where the developer really ment:
awk '/foo/ {print $1}'
 
Old 05-13-2011, 10:26 PM   #3
geehog
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Hi Couling,

No - I have a range of numbers i.e.
1 5
2 3
4 4
34 36
etc...

The above are Ranges (min max values): 1 through to 5, 2 through to 3, 4 through to 4, 34 through to 35 & so on...

Need to generate all numbers in these sequences (integers) .. 1,2,3,4,5 2,3 4 34,35 in a single column listing
1
2
3
4
5

2
3
4

34
35

Will then put this through a sort -u to remove duplicate numbers. With this new column list, will then use wc command to get the total count of individual number.

Issue with seq command is that it (appears) to only accept 1 row of numbers (i.e. unable to input multiple values of min max) to generate integer sequence numbers.
 
Old 05-13-2011, 11:46 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well I don't think you need the several different commands you are using, but as you hide some of the commands being piped in it is hard to know.
This would seem to solve what you have given us:
Code:
awk '{for(i=$1; i <= $2; i++)if(! (i in _))_[i]++}END{for(x in _)print x}' | sort -n
I am with Couling thought that using a useless grep that awk can already do serves no purpose except to make the code look convoluted.
 
1 members found this post helpful.
Old 05-14-2011, 12:18 AM   #5
geehog
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks Grail - is now solved. New to scripting - hence code is not as shorten as can be, plus also reading in various lines & sorting/filtering them through to the particular lines /items needed to get the pairs of min max numbers.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Transpose multiple rows into a single column wonjusup Linux - Newbie 13 04-09-2011 06:53 AM
awk multiple column into single column ilukacevic Programming 49 07-19-2010 07:23 PM
how to create a single line of output from multiple variable lines of input steven.c.banks Linux - General 2 02-03-2010 03:09 PM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 10:46 AM
Compiling multiple .c file using single command in makefile vipulc Linux - General 2 03-18-2006 11:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration