Все вопросы: [awk]

169 вопросов

похожие теги:
1
голосов
2ответов
1208 просмотров

Simplest method to get the dictionary definitions of a list of words in a text file

File1: hello world I don't know the best method to extract a list of words from a text file, find their definitions and paste them into an output textfile. I've been thinking of using WordNet - but don't know how to automate the process. Does anyone have any ideas (perhaps google/APIs/linux a...

5
голосов
5ответов
2638 просмотров

Move line(s) to follow another line in a file

I got a file that has a line in the file like this: check=('78905905f5a4ed82160c327f3fd34cba') I'd like to be able to move this line to follow a line that looks like this: files=('somefile.txt') The array though at times that can span multiple lines, for example: files=('somefile.txt' ...

1
голосов
5ответов
7497 просмотров

Remove strings after each first word in a text file

File1: hello (OPTION1) 123456 123456 123456 world (OPTION1) 123456 123456 123456 foo (OPTION1) 123456 123456 123456 bar (OPTION1) 123456 123456 123456 How would one remove each string after each first word in the textfile File1? This would probably be down...

2
голосов
3ответов
2645 просмотров

How to delete partial duplicate lines with AWK?

I have files with these kind of duplicate lines, where only the last field is different: OST,0202000070,01-AUG-09,002735,6,0,0202000068,4520688,-1,0,0,0,0,0,55 ONE,0208076826,01-AUG-09,002332,316,3481.055935,0204330827,29150,200,0,0,0,0,0,5 ONE,0208076826,01-AUG-09,002332,316,3481.055935,0204330...

2
голосов
4ответов
7495 просмотров

Output on a single line

The following code is working as expected. But I can not format the output. It will print something like this: mysql test someDB I want the output on a single line mysql test someDB I tried using sed in the script but it did not work. #!/bin/sh for dbName in `mysqlshow -uroot -pPassWord |...

693
голосов
35ответов
537551 просмотров

How to do a recursive find/replace of a string with awk or sed?

How do I find and replace every occurrence of: subdomainA.example.com with subdomainB.example.com in every text file under the /home/www/ directory tree recursively?

1
голосов
3ответов
2266 просмотров

How can I split a file into a given number of parts in Perl? (On Unix)

I have several large files, each of which I want to chunk/split it in to predefined number of parts. Is there an efficient way to do it in Unix (e.g. via awk/sed/perl)? Also each file can have varied number of lines. File1.txt 20,300,055 lines File2.txt 10,033,221 lines etc...

6
голосов
3ответов
7406 просмотров

convert exponential to decimal in python

I have an array in python that contains a set of values, some of them are 2.32313e+07 2.1155e+07 1.923e+07 11856 112.32 How do I convert the exponential formats to the decimal format Additional: Is there a way I can convert the exponent directly to decimal when printing out in UNIX with awk?

2
голосов
2ответов
1939 просмотров

Get only a part of the line using awk

I have a log file and i use awk to extract the required columns. My command is awk '{ print $2" "$5" " $6}' log.txt The $5 column contains the servername and the format can be like @:[email protected]:@:@:, [email protected]:@:@:@:@:, @:@:Server3 with no fixed amount of @: symbols. How do I modify my statemen...

0
голосов
5ответов
119 просмотров

problem in shell script

I am trying this option #!/bin/ksh echo $1 awk '{FS="=";print $2}' $1 and on the command line test_sh INSTANCE=VIJAY but awk is failing. Is there any problem here? Basically I need the value VIJAY passed on the command line.

-1
голосов
4ответов
212 просмотров

problem in a shell command

i am trying the following command on the command line ps -u `id | cut -f2 -d"=" | cut -f1 -d"("` -f | grep ppLSN | awk '{print $9}' | awk '{FS="=";print $2}' | grep KLMN | wc -l the value of teh command is returned as 7. but when i am putting the same command inside a script abc_sh like bel...

3
голосов
6ответов
44583 просмотров

awk command to accept two variables as parameters and return a value

I have a file which has 50 rows. Each row is made up of three columns. The first two columns are the variables and this will be passed as parameters to return the 3rd column's value. for ex.. command_file.txt is the file and it contains A B 10 C D 20 E F 30 G H 50 I J 70 ... I have a script w...

1
голосов
1ответов
118 просмотров

How can I embed arguments in an awk script?

This is the evolution of these two questions, here, and here. For mine own learning, I'm trying to accomplish two (more) things with the code below: Instead of invoking my script with # myscript -F "," file_to_process, how can I fold in the '-F ","' part into the script itself? How can I in...

0
голосов
8ответов
4943 просмотров

Compares lines in two files

how could we compare lines in two files using a shell script. I want to compare line in one file with the line in other.diff will give me all the differences in two files at a time.i want a line in the first file to be compared with all the lines in the second file and get the common lines as th...

2
голосов
2ответов
2478 просмотров

connect to a DB inside awk script

In a shell script we can connect to a Database using sqlplus on unix. can i perform the same thing inside an awk script? i need to access the output of a select query inside an awk script.is that possible?

0
голосов
2ответов
310 просмотров

script,unix,compare

I have two files ... file1: 002009092312291100098420090922111 010555101070002956200453T+00001190.81+00001295.920010.87P 010555101070002956200449J+00003128.85+00003693.90+00003128 010555101070002956200176H+00000281.14+00000300.32+00000281 file2: 002009092410521000098420090709111 0105604585200...

3
голосов
2ответов
1656 просмотров

Appending Text To the Existing First Line with Sed

I have a data that looks like this (FASTA format). Note that in comes with block of 2 ">" header and the sequence. >SRR018006 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN >SRR018006 ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC What I want to do is to append a text (e.g. "foo" in the> header) yiel...

0
голосов
2ответов
2091 просмотров

Shell script for getting the sequence and changing it?

I have a command like echo "abcd0001gfh.DAT" | sed 's/^[^0-9]*\(....\).*$//' | awk '{ print "00"$0 }' This will give me an output of 000001. But I want to run this in a loop where I receive the file name from 0001-9999 and again it becomes 0001. So my output should like below abcd0001gfh.D...

0
голосов
1ответов
1561 просмотров

Script for changing the sequence number on a file name

I am writing a shell script and I am stuck. The requirement is: I will receive files which have a sequence number on them like xyz0001abcd.DAT. I create a copy of that file, keeping the sequence number, as abcd000001gfh.DAT. The original filename uses four digits (up to 9999), and the copied one ...

18
голосов
13ответов
20829 просмотров

Converting FASTQ to FASTA with SED/AWK

I have a data in that always comes in block of four in the following format (called FASTQ): @SRR018006.2016 GA2:6:1:20:650 length=36 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN +SRR018006.2016 GA2:6:1:20:650 length=36 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+! @SRR018006.19405469 GA2:6:100:1793:611 length=36...

0
голосов
1ответов
1547 просмотров

Format of File using Awk in PowerShell

All I did was ls to a file, then ran a simple awk print. I'm new to both PowerShell and Awk, but the output is obsviously not what's expected. Can anyone explain this? Does it have something to do with the format of the file? PS C:\Documents and Settings\lmoser\My Documents\Test> awk '{ pr...

1
голосов
4ответов
4143 просмотров

How to rearrange columns

In a file I am reformatting, I would like to put the last column as the first and have the rest of the columns stay the same. I could do this easily in python, but thought I'd learn some awk this evening. Here is an example: (before) polk_describes:1 diatribe_that:1 #label#:negative (after)...

2
голосов
3ответов
669 просмотров

Count lines with awk, regardless of line ending style

What's the best way to count the number of line in a file with awk, regardless of line-ending style (DOS/Windows, UNIX, etc.)?

2
голосов
2ответов
685 просмотров

How can I collapse this bash command line into an awk statement?

I've created an awk script and use it like this: # grep -E "[PM][IP][DO][:S]" file.txt | awk-script How can I modify the awk script to include the effort of the grep command (which is searching for either "PID:" or "MPOS"? awk-script is: #!/usr/bin/awk -f /Sleeve/ { printf("%8d, %7d...

76
голосов
4ответов
163135 просмотров

Select row and element in awk

I learned that in awk, $2 is the 2nd column. How to specify the ith line and the element at the ith row and jth column?

4
голосов
5ответов
14875 просмотров

awk and printf in bash

I am trying to get the rounded number of the average load in the past 5 mins. So here goes my command: uptime | awk -F, '{print $5}'|printf "%.0f\n" It seems incorrect as it always give me 0. If I tried to use a variable as intermediate between awk and printf, then it is correct avgload=$(...

2
голосов
2ответов
878 просмотров

Use awk to add namespace to C# files

I have several C# classes where the namespace wasn't added to the file. A sample file looks like this (Test.cs): using System; using System.IO; public partial class MyTestClass { protected void MyTestVoid() { // Magic happens here } } As you can see there is no namespace d...

1
голосов
2ответов
594 просмотров

Extracting multiple columns without loop

I am writing an awk script that will take the output of grep and nicely format that into an HTML table. The delimiter is the ":" character; the problem I'm running into is that that character can appear in the text as well. So if I just use $1, $2, and $3 for the filename, line number, and comm...

2
голосов
4ответов
1449 просмотров

How can I selectively awk a string?

If text lines of indeterminate width had in a file had text "Line-to-reorder", and I only wanted to flip and display the order of the first three tokens I can do: # cat file.txt | awk '/Line-to-reorder/ { print $3 $2 $1 }' How can I let lines of text that don't have the matching criteria pass ...

0
голосов
3ответов
1421 просмотров

Ignoring escaped delimiters (commas) with awk?

If I had a string with escaped commas like so: a,b,{c\,d\,e},f,g How might I use awk to parse that into the following items? a b {c\,d\,e} f g