Need help in finding a Query


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help in finding a Query
# 1  
Old 07-29-2013
Need help in finding a Query

Can you help me in finding some query to arrange the below data.

If you see the portion labeled in Blue below, there is space in name in 1st line, no space in 2nd line & there are 3 characters in 3rd line.

We need to write one query in unix that it understands the name properly.

Code:
10.191.185.84 20/Jul/2013:15:53:17,115 3997900001173116 [POST /sds/menu HTTP/1.1] SEAHO Wireless  Apple4.0_IPad1x "iPad iPhone OS 6.1.3 TWC_4.0.0 mPSC_ISC-4.0-2.0" - 8 83 E3001 F 0 "application/octet-stream" 206
10.112.75.189 21/Jul/2013:21:04:26,731 8339800001441062 [POST /sds/menu HTTP/1.1] AdamBurkhalter Apple4.0_IPhone2x "iPhone2x iPhone OS 6.1.3 TWC_4.0.0 mPSC_ISC-4.0-2.0" - 8 84 E3001 F 0 "application/octet-stream" 606
10.191.185.84 20/Jul/2013:03:02:16,161 3997900001038728 [POST /sds/menu HTTP/1.1] jaime antonio perez Apple4.0_IPhone2x "iPod2x touch OS 6.1.3 TWC_4.0.0 mPSC_ISC-4.0-2.0" - 8 87 E3001 F 0 "application/octet-stream" 158

Moderator's Comments:
Mod Comment edit by bakunin: When we asked you to use CODE-tags we really meant it. Please use them yourself from now on. Thanks.

Last edited by bakunin; 07-30-2013 at 08:37 AM..
# 2  
Old 07-29-2013
Code:
cat a.a | cut -d\] -f2 | sed -e 's/Apple.*$//'

but this only works if Apple is in every line and no one has the name Apple
# 3  
Old 07-29-2013
Please use code tags as reqired by forum rules!

And, your specification is very poor. For you sample file, and only for that, try
Code:
sed 's/^[^]]*] \| Apple4.*$//g' file
SEAHO Wireless
AdamBurkhalter
jaime antonio perez

# 4  
Old 07-30-2013
Thanks Rudi C but apple will not be available in all the lines
# 5  
Old 07-30-2013
Quote:
Originally Posted by Vinod Chandar
Thanks Rudi C but apple will not be available in all the lines
Then, how are we supposed to find out where the name ends? Is there any element in the line you can point at and say: "if you see this you know the name part is over"?

I hope this helps.

bakunin
# 6  
Old 07-30-2013
Thanks Bakunin .. There is nothing specific where we can identify whether the name part is over .

I can explain you in detail .

Immediately after the name part the phone device model appears(Ex.
Code:
SEAHO Wireless  Apple4.0_IPad1x
AdamBurkhalter Apple4.0_IPhone2x
aime antonio perez Apple4.0_IPhone2x

it may be of any phone model like Apple,Samsung HTC etc..) and after the phone device model you can see device version within apostrophe "" ...
the username will be exactly on the 5th column(I am counting based on the space).

These are the only details I have it in the file.

Please let me know if you require more information.

Last edited by Vinod Chandar; 07-30-2013 at 09:29 AM..
# 7  
Old 07-30-2013
Code:
awk '{gsub(/.*\] |".*/,X);NF-=1}1' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

2. UNIX for Dummies Questions & Answers

Query

Hi, I have a script to remove null values from a file. Could any one explain how this is working? :confused: while read f do echo process $f gawk... (0 Replies)
Discussion started by: abhi_n123
0 Replies

3. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

4. UNIX for Dummies Questions & Answers

Query :: Using Netstat finding total value to a db connection

I wrote a very simple script to calculate the DB connection from an appserver and check the total netstat connection to a particular DB exceed 25 then it will send mail netstat -a 2> /dev/null | awk '/.*ESTAB/{print $5}' | cut -d. -f1 | uniq -c | awk '{if ($1 > 25)print $2," exceed ",$1;}' ... (1 Reply)
Discussion started by: senthil.ak
1 Replies

5. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

6. UNIX for Dummies Questions & Answers

Need Help on query

I just started to learn unix - need help to write a script to query a logfile and produce the results that contains a specific word "alarm" for a period from X day to Y day. I really have no idea how to begin - :( please help... ____________________________________________________ #... (1 Reply)
Discussion started by: snipfer
1 Replies

7. Shell Programming and Scripting

query

I have converted data written on excel sheet in unix through shell & perl prg now the problem is I want that if starting columns of the xls sheet is Blank than when data is converted into unix then it should appear with this '|' sign. but it appearing like this: hfgg|tytt| but I want like... (2 Replies)
Discussion started by: akash
2 Replies

8. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

9. UNIX for Dummies Questions & Answers

query

hi, how can i do the following..... i have file containing followig a k 10000 b c 200000 d e 50 a j 40 how can i list all rows containg last value more than 1000? and how can i find number of blank rows in the file? THANKS! regards vivek (2 Replies)
Discussion started by: vivekshankar
2 Replies
Login or Register to Ask a Question