grep -n help

2013-01-31  Source: Original Site  Category:Unix Shell Scripts  Views:1 

Advertisement

I am trying to create a script that greps a file for a character then returns the line number of that character. This is fine but when you use grep -n it returns the line number and the whole line of text. Is there away of getting it to just come back with the line number ?

example

cat filename | grep -n "="

this returns

16:============================================================================= ======================================================= 19:============================================================================= ======================================================= 22:============================================================================= ======================================================= 25:============================================================================= ======================================================= 28:============================================================================= ======================================================= 31:============================================================================= ======================================================= 35:============================================================================= ======================================================= 38:============================================================================= ======================================================= 41:============================================================================= ======================================================= 44:============================================================================= =======================================================

when all i need is the line number

Related articles
  • Ubuntu Grep Command Help 2014-12-18

    Greetings, I am Kevinesh. A new user to LINUX & Ubuntu. I don't understand about grep, awk, & sed command. Would prefer if anybody could help me out. Cause i am a Windows user previously migrating to LINUX as my future job needs to be support

  • The grep command (HELP!!) 2015-02-04

    Help! I'm trying to output any paragraph instance in a text file that a * occurs, i've used the command cat filename.txt |grep -p '*' but as * is a wildcard it throws out every paragraph in the file, and not just the ones that contain a * Is there an

  • grep -n help 2013-01-31

    I am trying to create a script that greps a file for a character then returns the line number of that character. This is fine but when you use grep -n it returns the line number and the whole line of text. Is there away of getting it to just come bac

  • grep command help~ 2013-02-09

    I have a log file name abc.log which contain my computer cpu usage: 0.0 rpc portmap 0.0 root xinetd -stayalive -pidfile /var/run/xinetd.pid 0.0 root /usr/sbin/sshd 0.0 root /usr/sbin/automount --timeout=60 /misc file /etc/auto.misc 0.0 root /usr/sbin

  • Ubuntu Some Epic grep guru help? 2014-12-03

    Edit: Scrap that, change to something that will just give the ip thats up in this format and append it to an new file like this 10.0.0.1 - - 10.0.0.2 - - 10.0.0.3 - - 10.0.0.138 - - So, i need to generate a nice host list from a nmap host file, probl

  • Ubuntu grep regex help 2014-12-26

    guys, I have a quick question that I am sure someone will be able to help me with. I am pretty new to using regular expressions. I know the basics, but am not very good with expression matching yet. So here is what I am trying to do: I have a directo

  • Ubuntu Links across the network 2012-05-24

    community, my first post to "the hive mind":). I have been using ubuntu for about 4 months now and I am loving the power! One thing is really frustrating me though and I'm sure I'm not the only one with the problem(I have seen simmilar posts but no r

  • Ubuntu HOWTO: Fixing the "Mesa Issue" for ATI Cards 2012-07-21

    Updated 10/21/2006. Note: Not quite applicable to Edgy yet; ie I haven't gotten fglrx working in edgy yet. If you have, please post your card and what you did! In the interim, a better guide is here (http://wiki.cchtml.com/index.php/Ubuntu_Installati

  • command to limit from displaying all 2013-09-17

    Does anyone knows linux/unix command to limit the number of lines from Displaying it. I tried man cat/grep no help on those. Any other commands where i could limit from displaying it. I do not want to use less or more command. I want to use number to

  • Ubuntu HOWTO: Recover Lost Disk Space 2014-01-24

    Disk Space Problems & Solutions This guide was created to help users who are having issues with disk space, or lack thereof. It presents various reasons why free space may have unexpectedly disappeared or changed, and how to locate and remove the

  • Help required on "grep" 2012-02-11

    I am new to shell scripting. My question is How to grep exact pattern from a variable in UNIX. This is the scenario. In the present server there are 3 oracle databases up and running, which are HRM83DEV, HRM83TST, HRM83CFG. There is no database/s cal

  • Ubuntu Grep script command help 2012-02-18

    Sure this isnt the right forum for this, but you are SOOO clever :) I need to create a script that will be actioned by a 2nd script, which in turn performs an action based on the first scripts response (think of it as an adhoc monitoring and response

  • I need some help with grep 2012-03-13

    I'm very new to shell scripting in Linux and would greatly appreciate any help. I am trying to write a script that quietly mounts any .dmg in a given folder when a user logs into OS X. I've already learned the login hook and I can write a script that

  • Ubuntu grep help please 2012-05-03

    I'm taking a class at the local Community College involving Ubuntu 8.10. We're into files and one of the assignments involves grep commands. The actual problem involves; Display the lines (in a text file) that contain at least five asterisks *****. I

  • Ubuntu Need help with a script to extract numbers from a grep stream 2012-09-12

    I need to pass the PID number to a kill command using a simple shell script. Here's what I need to do in easy steps: 1. Get the PID # of the process, the closest I can get is with: screen -list | grep Detthis gives the following output: 19729.omnibot

  • noob - grep help 2012-10-19

    Just getting into Linux after a job move and have been asked to produce a GREP string that will list all the files owned by the root user and for this list to be stored in a file called “root_owned_files”. I understand the basics of grep but have no

  • help with awk and grep 2012-10-30

    i am tring to take out a line from a specific file by using the grep command the a specific file i find pipe the awk command on ps -ef ,in ps -ef the dir+name of the file appear at the 10th character . I wrote a little script but it doesnt work can s

  • Ubuntu Bash - grep with user specified pattern [help] 2012-11-23

    there. I'm having trouble getting this script to work right. I want to input a pattern for grep, 'mtu' for instance, but having $zSearch instead of 'mtu' doesn't work. Here is the script. #!/bin/bash read -p "Enter the target directory to search:" zT

  • Urgent help on Linux questions. grep & awk 2012-11-30

    Can someone help me on these questions please? 1) Write an awk program that takes data from an input file with two columns: student names and student grades, then adds a third column to each student's record, with PASS or FAIL, depending on the earne

  • need help with grep 2012-12-13

    I'm trying to find queries with multiple lines: $query = "insert into {$db_name}.tbl_memo values ('xxx', xxx, ....) Anyone help me with "grep" command to find these strings cross multiple lines? Thx