Help me with file conversion [Shell Script]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me with file conversion [Shell Script]
# 1  
Old 09-25-2009
Help me with file conversion [Shell Script]

Hello Group,

I request your help with a shell script for filter an ascii file (this is small piece of the file):

Code:
09/24/2009,00:00,1.0268,1.0268,1.0249,1.0250,518
09/24/2009,01:00,1.0251,1.0261,1.0249,1.0259,424
09/24/2009,02:00,1.0258,1.0272,1.0258,1.0269,372
09/24/2009,03:00,1.0270,1.0276,1.0266,1.0270,389
09/24/2009,04:00,1.0269,1.0277,1.0267,1.0268,488
09/24/2009,05:00,1.0267,1.0275,1.0262,1.0269,575
09/24/2009,06:00,1.0270,1.0271,1.0248,1.0248,670
09/24/2009,07:00,1.0249,1.0254,1.0238,1.0238,1314
09/24/2009,08:00,1.0239,1.0259,1.0238,1.0240,1111
09/24/2009,09:00,1.0241,1.0245,1.0219,1.0220,1291
09/24/2009,10:00,1.0221,1.0242,1.0207,1.0236,1389
09/24/2009,11:00,1.0237,1.0241,1.0221,1.0221,1049
09/24/2009,12:00,1.0220,1.0235,1.0210,1.0216,1189
09/24/2009,13:00,1.0215,1.0249,1.0211,1.0237,1125
09/24/2009,14:00,1.0239,1.0290,1.0238,1.0268,1837
09/24/2009,15:00,1.0269,1.0292,1.0264,1.0278,1290
09/24/2009,16:00,1.0277,1.0282,1.0262,1.0273,874
09/24/2009,17:00,1.0272,1.0322,1.0268,1.0319,1080
09/24/2009,18:00,1.0318,1.0320,1.0299,1.0300,674
09/24/2009,19:00,1.0301,1.0305,1.0291,1.0298,636
09/24/2009,20:00,1.0299,1.0304,1.0292,1.0293,220
09/24/2009,21:00,1.0295,1.0298,1.0282,1.0293,332
09/24/2009,22:00,1.0292,1.0299,1.0291,1.0298,183
09/24/2009,23:00,1.0297,1.0315,1.0290,1.0296,543
09/25/2009,00:00,1.0295,1.0319,1.0290,1.0310,669

The second field above correspond to the hour and I need only the hours between 12:00 and 22:00 and discard the others rows.

I have Ubuntu in my computer

I really appreciate it your help

Sincerely,

Carlos

Last edited by vgersh99; 09-25-2009 at 02:49 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-25-2009
Something like this?

Code:
awk -F",|:" '$2 > 11 && $2 < 23' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 09-25-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 09-25-2009
Ad hoc:

Code:
#! /bin/bash

cat ascii.file | \
while read LINE
do
  TIME=$( echo $LINE | awk -F ',' '{ print $2 }' | sed 's/://' )
  if [ $TIME -ge 1200 ] && [ $TIME -le 2200 ]
  then
    echo "$LINE"
  fi
done

exit 0

This User Gave Thanks to dr.house For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies

2. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

3. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

4. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

5. Shell Programming and Scripting

Shell Script for Epoch Time Conversion

Hi there I came across this script online to convert Epoch time to proper date format, but I am receiving the following error Also, I have HISTTIMEFORMAT set in user's .profile so that their history output shows time stamps. Additionally I have changed their .history location to a dedicated... (9 Replies)
Discussion started by: hedkandi
9 Replies

6. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

7. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

8. Shell Programming and Scripting

Shell script for CSV conversion

thanks for allowing me join your forum i have an output of linux command "who" which provides following details..... CURRENT USER/ACCT INFO 17:31:36 up 4:49, 4 users, load average: 0.03, 0.04, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - 12:59 ?xdm? 4:54 0.02s /bin/sh /usr/bi... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

9. AIX

Need timestamp conversion shell script !!

Can anyone provide me with a ksh or bash script which will accept a timestamp (format is YYYY-MM-DD-HH24.Mi.Ss) and time offset (in hours). The output will be (timestamp passed - time offset passed deducted from it) in the same YYYY-MM-DD-HH24.Mi.Ss format. Basically I am trying to convert the... (1 Reply)
Discussion started by: shibajighosh
1 Replies

10. Shell Programming and Scripting

shell script conversion to binary

My question is: i have a script called getevent to run i just call ./getevent can i convert this to make it binary executable and not letting my clients open it and see the code.??:( I am using Solaris 8. (3 Replies)
Discussion started by: bcheaib
3 Replies
Login or Register to Ask a Question