Search Results

Search found 2743 results on 110 pages for 'awk formatting'.

Page 2/110 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • using Awk inside Perl script

    - by papoyan
    My first question in stackoverflow! I'm having trouble using the following code inside my perl script, any advise is really appreciated, how to correct the syntax? # If I execute in bash, it's working just fine bash$ whois google.com | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ ) { print $i}}}'|head -n1 [email protected] #----------------------------------- #but this doesn't work bash$ ./email.pl google.com awk: {for (i=1;i<=NF;i++) {if ( ~ /[[:alpha:]]@[[:alpha:]]/ ) { print }}} awk: ^ syntax error # Here is my script bash$ cat email.pl ####\#!/usr/bin/perl $input = lc shift @ARGV; $host = $input; my $email = `whois $host | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ ) { print $i}}}'|head -1`; print my $email; bash$ Thank you in advance !

    Read the article

  • How to use a variable in an awk expression

    - by lugte098
    I'm trying to make this command: sed bla bla filename | awk '{printf "%s %s_entry_%.3f %.3f %.3f %.3f",$1,$3,$4,$5,$6,$7}' But the thing is, i want the %.3f part to be variable. So in one case it could be %.3f and in another it could be %.3f %.3f %.3f. So i'll just use a static one in my example code for clarity. So if i want 4 of these %.3f and put them in variable $values like so: values="%.3f %.3f %.3f %.3f" Then how can i put this string in the awk expression, without making awk to just put literally "${values}" in there. The following is my non-working-attempt: sed bla bla filename | awk '{printf "%s %s_entry_${values}",$1,$3,$4,$5,$6,$7}'

    Read the article

  • sed/awk or other: increment a number by 1 keeping spacing characters

    - by WizardOfOdds
    I've got a string: (notice the spacing) eh oh 37 and I want it to become: eh oh 36 (so I want to keep the spacing) Using awk I don't find how to do it, so far I have: echo "eh oh 37" | awk '$3>=0&&$3<=99 {$3--} {print}' But this gives: eh oh 36 (the spacing characters where lost, because the field separator is ' ') Is there a way to ask awk something like "print the output using the exact same field separators as the input had"? Then I tried with sed, but got stuck after this: echo "eh oh 37" | sed -e 's/\([0-9][0-9]\)/.../' Can I do arithmetic from sed using a reference to the matching digits and have the output not modify the number of spacing characters? Note that it's related to my question concerning Emacs and how to apply this to some (big) Emacs region (using a replace region with Emacs's shell-command-on-region) but it's not an identical question: this one is specifically about how to "keep spaces" when working with awk/sed/etc.

    Read the article

  • Awk filtering values between two files when regions intersect (any solutions welcome)

    - by user964689
    This is building upon an earlier question Awk conditional filter one file based on another (or other solutions) I have an awk program that outputs a column from rows in a text file 'refGene.txt if values in that row match 2 out of 3 values in another text file. I need to include an additional criteria for finding a match between the two files. The criteria is inclusion if the range of the 2 numberical values specified in each row in file 1 overlap with the range of the two values in a row in refGene.txt. An example of a line in File 1: chr1 10 20 chr2 10 20 and an example line in file 2(refGene.txt) of the matching columns ($3, $5, $ 6): chr1 5 30 Currently the awk program does not treat this as a match because although the first column matches neither the 2nd or 3rd columns do no. But I would like a way to treat this as a match because the region 10-20 in file 1 is WITHIN the range of 5-30 in refGene.txt. However the second line in file 1 should NOT match because the first column does not match, which is necessary. If there is a way to include cases when any of the range in file 1 overlaps with any of the range in refGene.txt that would be really helpful. It should also replace the below conditional statements as it would also find all the cases currently described below. Please let me know if my question is unclear. Any help is really appreciated, thanks it advance! (solutions do not have to be in awk) Rubal FILES=/files/*txt for f in $FILES ; do awk ' BEGIN { FS = "\t"; } FILENAME == ARGV[1] { pair[ $1, $2, $3 ] = 1; next; } { if ( pair[ $3, $5, $6 ] == 1 ) { print $13; } } ' $(basename $f) /files/refGene.txt > /files/results/$(basename $f) ; done

    Read the article

  • redirection of awk print to a file

    - by sushil kumar
    I can get the cpu Mhz of a solaris machine by following command. % /usr/sbin/psrinfo -v | grep operate |head -1 | awk '{print $6}' 1200 when I run the following command, awk output is not getting redirected. % csh -cf "/usr/sbin/psrinfo -v | grep operate |head -1 | awk '{print $6}' > myoutput" % cat myoutput The sparcv9 processor operates at 1200 MHz, how to get following result % cat myoutput 1200

    Read the article

  • Awk appears to disconnect my DB2 session when piping

    - by greggannicott
    Hello. I'm attempting to run the following command in Korn Shell (ksh): set -A INDEXES `db2 "describe indexes for table ${TABSCHEMA}.${TABNAME} show detail" | awk '{print $1"."$2}'` What I'm attempting to achieve is place a list of the indexes over a particular table into an array which I can later iterate through. The problem is, when I run the above command the contents of the array starts with the error message of 'SQL1024N' (which is telling me that the database connection does not exist). However, if I remove the 'awk' at the end of the statement as so: set -A INDEXES `db2 "describe indexes for table ${TABSCHEMA}.${TABNAME} show detail"` it works just fine (well, to the extent its returning data. Obviously without the awk I'm not capturing the correct data). Does anyone know why the awk is having this affect? I appreciate there is more than one way to get this data, but it baffles me as to why this is happening. Thanks in advance. Greg.

    Read the article

  • Is it possible to have a conditional formatting cell "visually cycle" through all the formats that evaluated true?

    - by Ben
    Like the title says, "In Excel, when a cell has multiple conditional formatting rules that evaluate true, is it possible to have the cell "visually cycle" through all the formats that evaluated true? If not, suggestions on what to do would be appreciated!" I'm creating an employee schedule for a business that has multiple job areas that need to have an employee assigned to cover. The schedule is currently set up with the date on the top row, employee list down the left column, and the employee's assigned "job area" cross-referencing with the date on the top row. Originally it was set up where if every required "job area" didn't have someone assigned to it, the date would (via conditional formatting) change to red. I've set it up now that if a condition isn't met, the date will change to the color of the "job area" that doesn't have an employee assigned to it. However, there are cases where multiple job areas don't have an employee assigned, but the date will only change color based on the first condition that isn't met. It'd be nice if there was some way for the date cell to cycle through the different colors that correspond to the job areas where no one is assigned. I have a hunch that's not possible though. If it is possible, I'd love to know how to do it. And if it isn't, if anyone has any suggestions on how I can modify the Excel sheet to make it easier to identify the job areas that don't have anyone assigned to them, I would appreciate it. FYI This schedule goes out months in advance.

    Read the article

  • Using Find, Grep, Awk, or Sed To Rename Server After Cloning

    - by ServerChecker
    My client tells me they have cloned a VM in VMWare of an Ubuntu Linux server. Now it's my job to get into all the files and find out what still has the old server name of "bishop" and change it to something else. Also, the IP address is changed and I need to search for that too. How would you typically use find, grep, awk, or sed to find these files and then change them rapidly? In the end, I want to make a Bash script. Of course, I'm not expecting you to tell me every file, but just want to know the technique for finding files with "x" in it and then switching that rapidly with "y".

    Read the article

  • Need help on awk/sed/ perl pattern with regex / grep

    - by Jayakumar K
    Sample file output from grep file1:my $dbh = DBI->connect("dbi:mysql:$database_name", $DB_USER, $DB_PASSWD) file2:($dbc,$rc) = mysql_connect($mysql_host,$mysql_user,$mysql_password); The awk pattern should get values databasename, DB_USER And DB_PASSWD from line 1 and mysql_host,mysql_user and mysql_password from line 2 i.e all variables inside the function. Then it should search for the declaration of that variable in file before : (semicolon) ex: databasename in file1 may be $databasename = "dbweb" ; ex: mysql_user in file2 may be $mysql_user="root" ; Result: It should display variable declarations of all 6 variables along with filenames file2:$mysql_host = "db1"; file2:$mysql_user = "root"; file1:$DB_USER = 'user';

    Read the article

  • how to substitude in multiple lines between {{{ and }}} with sed or awk

    - by chris
    First give out the text example: .... text ,.. {{{python string1 = 'abcde' string2 = '12345' print(string1[[1:3]]) print(string2[[:-1]]) }}} .... text ,.. the [[ and ]] happened outside of {{{ too. And maybe there is spaces and tabs before {{{ and }}}. I want to substitude all [[ and ]] into [ and ] between {{{ and }}}. NOTICE: I need to write the result back to original file. ( Maybe sed or awk is not the only way to do this ? )

    Read the article

  • linux + create host file from CSV file by sed or awk or perl

    - by yael
    I have the following CSV file this file defined which Linux machine exist in the system and there ip's my target is to create host file from this file please advice how to create host file as example 1 from my CSV file ( I need to match the IP address from CSV file and put it on the first field of the host file , then match the LINUX name and locate this name in the sec field – as example 1 ) remark - should be performed by sed or awk or perl .. , I need to write the solution in my bash script CSV file , machine , VM-LINUX1 , SZ , Phy , 10.213.158.18 , PROXY , VM-LINUX2 , SZ , 10.213.158.19 , OLD HW , VM-LINUX3 , SZ , 10.213.158.20 , , VM-LINUX4 , SZ , Phy , 10.213.158.21 , , VM-LINUX5 , SZ , Phy , OUT , EXT , LAN3 , 10.213.158.22 , INTERNAL , VM-LINUX6 , SZ , Phy , 10.213.158.23 , , server , new HW , VM-LINUX7 , SZ , Phy , 10.213.158.24 , OUT, LAN3 , VM-LINUX8 , SZ , 10.213.158.25 , OLD HW , machine , VM-LINUX9 , SZ , Phy , INT , 10.213.158.26 , LAN2, AN45, , VM-LINUX10 , SZ , Phy , 10.213.158.27 , , VM-LINUX11 , SZ , Phy , LAN5 , 10.213.158.28 , example 1 ( host file ) 10.213.158.18 VM-LINUX1 10.213.158.19 VM-LINUX2 10.213.158.20 VM-LINUX3 10.213.158.21 VM-LINUX4 10.213.158.22 VM-LINUX5 10.213.158.23 VM-LINUX6 10.213.158.24 VM-LINUX7 10.213.158.25 VM-LINUX8 10.213.158.26 VM-LINUX9 10.213.158.27 VM-LINUX10 10.213.158.25 VM-MACHINE8 10.213.158.26 STAR9 10.213.158.27 TOP10 10.213.158.28 SERVER11

    Read the article

  • how to delete a line from file using awk filtered by some string

    - by embedded
    I have a file delimited by space. I need to write an awk command that receives a host name argument and it should replace the host name if it already defined in the file. It must be a full match not partially - if the file contains this host name: localhost searching for "ho" will fail and it will be added to the end of the file. another option is a delete: again awk receives host name argument and it should remove it from the file if exists. This is what I have so far: (It needs some enhancements) if [ "$DELETE_FLAG" == "" ]; then # In this case the entry should be added or updated # if clause deals with updating an existing entry # END clause deals with adding a new entry awk -F"[ ]" "BEGIN { found = 0;} \ { \ if ($2 == $HOST_NAME) { \ print \"$IP_ADDRESS $HOST_NAME\"; \ found = 1; \ } else { \ print \$0; \ } \ } \ END { \ if (found == 0) { \ print \"$IP_ADDRESS $HOST_NAME\"; } \ } " \ /etc/hosts > /etc/temp_hosts else # Delete an existing entry awk -F'[ ]' '{if($2 != $HOST_NAME) { print $0} }' /etc/hosts > /etc/temp_hosts fi Thanks

    Read the article

  • VIM with iA Writer type formatting?

    - by Ambidex
    I've been Googling for a while now. I would like to have iA Writer-like (or a bit like StackExchange) formatting in Vim. Since I love the way it formats my texts, but I'm constantly pressing "w" to skip words because my experience with Vim. I would love to be able to have the same smart formatting in Vim. I did found a nice Vim plugin for getting Vim to toggle to big and clean font: https://github.com/honza/writer.vim But this still does not enable me to use the formatting: # Header 1 ## Header 2 *underline* **strong** etc... Besides all this above, I would not mind to have Vim like shortcuts in my iA writer app if it would not be possible to implement iA formatting in Vim. Edit: After a while of even more searching, I found out this type of formatting is called Markdown. I am starting to think there isn't really a good way to directly edit a Markdown file in Vim, because Vim is not able to make things display like that? I would really like to be able to use the movement shortcuts in combination of the nice formatting of Markdown and how it is displayed in iA Writer.

    Read the article

  • Formatting php, what works more efficiently?

    - by JamesM-SiteGen
    Hello fellow programmers, I was just wondering what makes php work faster, I have a few methods that I always go and do, but that only improves the way I can read it, but how about the interpreter? Should I include the curly braces when there is only one statement to run? if(...){ echo "test"; } # Or.. if(...) echo "test"; === Which should be used? I have also found http://beta.phpformatter.com/ and I find the following settings to be good, but are they? Indentation: Indentation style: {K&R (One true brace style)} Indent with: {Tabs} Starting indentation: [1] Indentation: [1] Common: [x] Remove all comments [x] Remove empty lines [x] Align assignments statements nicely [ ] Put a comment with the condition after if, while, for, foreach, declare and catch statements Improvement: [x] Remove lines with just a semicolon (;) [x] Make normal comments (//) from perl comments (#) [x] Make long opening tag (<?php) from short one (<?) Brackets: [x] Space inside brackets- ( ) [x] Space inside empty brackets- ( ) [x] Space inside block brackets- [ ] [x] Space inside empty block brackets- [ ] Tiny var names: often I go through my code and change $var1 to $a, $var2 to $b and so on. I do include comments at the start of the file to show to me what each letter(s) mean.. Final note: So am I doing the right thing with the curly braces and the settings? Are there any great tips that help it run faster?

    Read the article

  • AWK If/ElseConditional Problem

    - by neversaint
    I have a data that looks like this: foo foo scaffold_7 1 4845 6422 4845 bar bar scaffold_7 -1 14689 16310 16310 What I want to do is to process the above lines where I just want to print column 1,2,3, 7 and one more column after 7th. But with condition when printing column 7 onwards. Below is my awk script: awk '{ if ($4=="+") { {end=$6-$5}{print $1 "\t" $2 "\t" $3 "\t" $4 "\t" $7 "\t" end+$7} } else {end=$6-$5}{print $1 "\t" $2 "\t" $3 "\t" $4 "\t" $7-end "\t" $7} }' But why it doesn't achieve the desired result like this? foo foo scaffold_7 1 4845 6422 bar bar scaffold_7 -1 14689 16310 Note that the arithmetic (e.g. $7-end or end+$7) is a must. So we can't just swap column from input file. Furthermore this AWK will be inside a bash script.

    Read the article

  • READING stderr from within Awk

    - by Dave
    I want to keep SSH debug info separate (and logged) from other input. However, if I simply redirect stderr to a log file, I risk combining output from SSH and output from the remote process on the host machine (that might send something to stderr): $ ssh -v somemachine 2 file.log So, I want to filter out only those lines that match "debug1": $ ssh -v somemachine | awk '/debug1/ {print "file.log"; next} {print}' Good so far, BUT ssh's debug output goes to stderr. So... $ ssh -v somemachine 2& | awk '/debug1/ {print "file.log"; next} {print}' Foiled again! I don't want to mix stdout and stderr. BAD! What does a kid like me do? I was about to go the route of named pipes or some such wildeness, but really, all I need to know is how to get awk to match patterns from stderr ONLY.

    Read the article

  • c, pass awk syntax as argument to execl

    - by Skuja
    I want to run following command in c to read systems cpu and memory usage: ps aux|awk 'NR > 0 { cpu +=$3; ram+=$4 }; END {print cpu,ram}' I am trying to pass it to execl command and after that read its output: execl("/bin/ps", "/bin/ps", "aux|awk", "'NR > 0 { cpu +=$3; ram+=$4 }; END {print cpu,ram}'",(char *) 0); but in terminal i am getting following error: ERROR: Unsupported option (BSD syntax) I would like to know how to properly pass awk as argument to execl?

    Read the article

  • Awk or Sed: File Annotation

    - by lukmac
    Hallo, my SO friend, my question is: Specification: annotate the fields of FILE_2 to the corresponding position of FILE_1. A field is marked, and hence identified, by a delimiter pair. I did this job in python before I knew awk and sed, with a couple hundred lines of code. Now I want to see how powerful and efficient awk and sed can be. Show me some masterpiece of awk or sed, please! The delimiter pairs can be configured in FILE_3, but let's assume the first delimiter in a pair is 'Marker (number i) start', the other one is 'Marker (number i) done' Example: |-----------------FILE_1------------------| text text text text blabla Marker_1_start Marker_1_done any text in between blabla Marker_2_start Marker_2_done text text |-----------------FILE_2------------------| Marker_1_start 11 1111 Marker_1_done Marker_2_start 2222 22 Marker_2_done Expected Output: |-----------------FILE_Out------------------| text text text text blabla Marker_1_start 11 1111 Marker_1_done any text in between blabla Marker_2_start 2222 22 Marker_2_done text text

    Read the article

  • Formatting Dates, Times and Numbers in ASP.NET

    Formatting is the process of converting a variable from its native type into a string representation. Anytime you display a DateTime or numeric variables in an ASP.NET page, you are formatting that variable from its native type into some sort of string representation. How a DateTime or numeric variable is formatted depends on the culture settings and the format string. Because dates and numeric values are formatted differently across cultures, the .NET Framework bases its formatting on the specified culture settings. By default, the formatting routines use the culture settings defined on the web server, but you can indicate that a particular culture be used anytime you format. In addition to the culture settings, formatting is also affected by a format string, which spells out the formatting details to apply. The .NET Framework contains a bounty of format strings. There are standard format strings, which are typically a single letter that applies detailed formatting logic. For example, the "C" format specifier will format a numeric type as a currency value; the "Y" format specifier displays the month name and four-digit year of the specified DateTime value. There are also custom format strings, which display a apply a very specific formatting rule. These custom format strings can be put together to build more intricate formats. For instance, the format string "dddd, MMMM d" displays the full day of the week name followed by a comma followed by the full name of the month followed by the day of the month. For more involved formatting scenarios, where neither the standard or custom format strings cut the mustard, you can always create your own formatting extension methods. This article explores the standard format strings for dates, times and numbers and includes a number of custom formatting methods I've created and use in my own projects. There's also a demo application you can download that lets you specify a culture and then shows you the output for the standard format strings for the selected culture. Read on to learn more! Read More >

    Read the article

  • bash/sed/awk/etc remove every other newline

    - by carillonator
    a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active unoptimized Runtime Name: vmhba3:C0:T3:L14 Group State: active Runtime Name: vmhba2:C0:T2:L14 Group State: active I'd like to pipe it to something to make it look like this: Runtime Name: vmhba2:C0:T1:L14 Group State: active Runtime Name: vmhba3:C0:T3:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T2:L14 Group State: active [...] i.e. remove every other newline I tried ... |tr "\nGroup" " " but it removed all newlines and ate up some other letters as well. thanks

    Read the article

  • awk + remove all not uniq lines except the first line uniq (FILE NAME)

    - by yael
    hi I have the following file How to remove by sed all FILE NAME lines except the first uniq FILE NAME For example need to remove all FILE NAME lines from the file except the first: FILE NAME: /dir1/dir2/dir3/dir4/dir5/file FILE NAME: /dirA/dirB/dirC/dirD/dirE/file the file: FILE NAME: /dir1/dir2/dir3/dir4/dir5/file PARAMETER NAME: blablabla TARGET FILE: 12 SOURCE FILE: 565 FILE NAME: /dir1/dir2/dir3/dir4/dir5/file PARAMETER NAME: blablabla TARGET FILE: 18 SOURCE FILE: 552 FILE NAME: /dir1/dir2/dir3/dir4/dir5/file PARAMETER NAME: blablabla TARGET FILE: 14 SOURCE FILE: 559 FILE NAME: /dirA/dirB/dirC/dirD/dirE/file PARAMETER NAME: blablabla TARGET FILE: 134 SOURCE FILE: 344 FILE NAME: /dirA/dirB/dirC/dirD/dirE/file PARAMETER NAME: blablabla TARGET FILE: 13 SOURCE FILE: 445 FILE NAME: /dirA/dirB/dirC/dirD/dirE/file PARAMETER NAME: blablabla TARGET FILE: 13 SOURCE FILE: 434

    Read the article

  • split a textfile after each n matches to a new file using sed or awk

    - by ozz
    i tried to split a file in parts of n matches each. The file is just one line and the seperator is '<br>' foo<br>bar<br>.....<br> I just want to split the file in parts, where each file has 100 datasets (text plus <br>)( normaly 100 datasets, but at the end maybe less) I already played around with this ... split-file-in-2-with-sed and this split-one-file-into-multiple-files-based-on-pattern sed.exe -e "^.*.<br>{0,100}/g" < original.txt > first_half.txt The split do not work an the result is only 1 file instead of many.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >