Sponsored Content
Full Discussion: Working with grep and Bash
Top Forums Shell Programming and Scripting Working with grep and Bash Post 302770883 by Njzangel on Monday 18th of February 2013 10:12:21 PM
Old 02-18-2013
Hi sorry guys for the late response I managed to figure out how to extract all my information and send them to variables. It maybe sloppy but right now it doesn't matter.

What I was looking for is lets say I have some lines like this
Code:
<div class="feed-item-content-wrapper clearfix context-data-item" data-context-item-title="Mike Chang's Superbowl Workout - Part II" data-context-item-user="sixpackshortcuts" data-context-item-views="114,925 views" data-context-item-id="V1l1TGUUaj0" data-context-item-type="video" data-context-item-time="8:44" data-context-item-actionuser="sixpackshortcuts">

I would need to Extract the Views, duration(time) username, and title. Which I did using these simple codes and passed them to a variable
Code:
#! /bin/bash

#wget -O web2.html youtube.com

echo [Views]            [time/Duration] 
echo ----------------------------------
echo    

views=$(grep views web2.html | grep -v 'div' | cut -d ' ' -f5 | tr -d ',')

users=$(grep item-user web2.html | cut -d '"' -f6)

duration=$(grep item-time web2.html | grep -o '"[^"]*"' | grep : | grep -vi '[a-z]' | tr -d '"')

title=$(grep item-title web2.html | cut -d '"' -f4)

So lets say I echo "$views" it will show something like

11
2244
2423532
2342
2324

echo $title

I'm hungry
Pewdiepie rocks

My issue now is as you can see in the code its incomplete, I have to construct a table with columns and display all my data in columns. I have no idea what soever where to start I need it to show up like

[Views]---------[Title]--------------------[user]
12 ------------Pewdiepie--------------Pewdiepie
1212 --------IDONTCARE!--------Somedeadguy
1212 --------BARRELS!!-----------idonthavewifi
1 --------------Poop]--------------------etc

(minus the '-' it was used for an example to look more clear)
and so on with the time duration. How can i go about outputting the contents of the variables in such a way?
 

10 More Discussions You Might Find Interesting

1. Solaris

grep -r isn't working

Hi, I was trying to use this particular option of grep grep -r 'Search_pattern' * This command should ideally search all the occurrences of Search_pattern recursively within a directory & print it on shell prompt. But this command is not doing what is expected. It just displays nothin! ... (8 Replies)
Discussion started by: harishmitty
8 Replies

2. UNIX for Dummies Questions & Answers

grep not working

This condition is not able to grep , can any one tell what's wrong with this part. I am able to see from unix command but not with host script. echo "Checking for Loader Status " >> $REPFILE if test $? = 0 then echo "Successful termination of SQL*Loader "$LOADER1 >>... (5 Replies)
Discussion started by: u263066
5 Replies

3. HP-UX

Why Bash is not working in HP-UX ?

Why Bash is not working in HP-UX ? What is similiar exe which is in HP_UX as Bash? (9 Replies)
Discussion started by: girija
9 Replies

4. Shell Programming and Scripting

grep not working ????

Hi, I've prob in doing grep. I want to grep line staring with number 531250 in the 1st column from a file (example in picture attached below) using command grep -w "531250" file my ideal result should be 531250 1 21 42.1 100 1e-05 ... (8 Replies)
Discussion started by: masterpiece
8 Replies

5. Shell Programming and Scripting

Working with bash and date

Hello all, I'm trying to substract 1 minute from the current date and take the hour and minute (for filename purpose). 1) If I want hour an minute from current time I can use: timetmp=$(date +"%H:%M") 2) To substract 1 minute from current time I can use: timetmp=$(date --date "$dte -1... (8 Replies)
Discussion started by: Lord Spectre
8 Replies

6. UNIX for Dummies Questions & Answers

grep -f not working

Hello, I'm going crazy about this. I'm using grep to filter some values as in pas -ef | grep asterisk. When I use the same with -f somefile something weird happens, if somefile is created with vi it'll work, if somefile is created with vi but values are pasted from an Excell file it will not work.... (2 Replies)
Discussion started by: seveman
2 Replies

7. UNIX for Dummies Questions & Answers

grep for word not working

Hi All..I need a help i am trying to find a word using below script whereas the word exists in my file nitin.txt as a directory but still i am getting "word not found" output..Your suggestions welcomed.: #to check for existence of nitin #!/bin/bash cd /apps/uat1/deploy/app ls -lrt >... (4 Replies)
Discussion started by: nattynitin
4 Replies

8. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

9. Shell Programming and Scripting

Grep not working on mac

Hi all, I got a new mac and can't get grep, awk etc to work. I tried the following command: grep DICER test.txt output: AGOER text.txt looks like this: DICER DICER AGOWhat is wrong? Please use code tags (23 Replies)
Discussion started by: Palgrave
23 Replies

10. Programming

Best way to get a bash script working in C

Ahoy friends. Currently i got a bash script running to manage my minecraft servers. All of them are stored in /home/minecraft_servers directory. Using my script im able to start a server (e.g. ./minecraft start ftb_continuum) because server name and server name are the same.(e.g.... (2 Replies)
Discussion started by: Knogle
2 Replies
ZGREP(1)						    BSD General Commands Manual 						  ZGREP(1)

NAME
zgrep, zegrep, zfgrep -- print lines matching a pattern in gzip-compressed files SYNOPSIS
zgrep [grep-flags] [--] pattern [files ...] zegrep [grep-flags] [--] pattern [file ...] zfgrep [grep-flags] [--] pattern [file ...] DESCRIPTION
zgrep runs grep(1) on files or stdin, if no files argument is given, after decompressing them with zcat(1). The grep-flags and pattern arguments are passed on to grep(1). If an -e flag is found in the grep-flags, zgrep will not look for a pattern argument. zegrep calls egrep(1), while zfgrep calls fgrep(1). EXIT STATUS
In case of missing arguments or missing pattern, 1 will be returned, otherwise 0. SEE ALSO
egrep(1), fgrep(1), grep(1), gzip(1), zcat(1) AUTHORS
Thomas Klausner <wiz@NetBSD.org> BSD
December 28, 2003 BSD
All times are GMT -4. The time now is 01:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy